Given a positive integer n, print first k digits after point in value of 1/n. Your program should avoid overflow and floating point arithmetic.
Input: n = 3, k = 3 Output: 333 Input: n = 50, k = 4 Output: 0200
We strongly recommend to minimize the browser and try this yourself first.
Let us consider an example n = 7, k = 3. The first digit of 1/7 is ‘1’, it can be obtained by doing integer value of 10/7. Remainder of 10/7 is 3. Next digit is 4 which can be obtained by taking integer value of 30/7. Remainder of 30/7 is 2. Next digits is 2 which can be obtained by taking integer value of 20/7
This article is contributed by Sachin. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count of digits after concatenation of first N positive integers
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
- Minimum digits to be removed to make either all digits or alternating digits same
- Minimum positive integer to divide a number such that the result is an odd
- Minimum positive integer divisible by C and is not in range [A, B]
- Maximum positive integer divisible by C and is in the range [A, B]
- Count pairs in Array whose product is a Kth power of any positive integer
- Count of index pairs in array whose range product is a positive integer
- Smallest positive integer X satisfying the given equation
- Minimum positive integer value possible of X for given A and B in X = P*A + Q*B
- Count positive integers with 0 as a digit and maximum 'd' digits
- Minimum Possible sum of digits in a positive multiple of N
- Find the smallest positive number which can not be represented by given digits
- Find the number of positive integers less than or equal to N that have an odd number of digits
- Nth positive number whose absolute difference of adjacent digits is at most 1
- Minimum number of changes such that elements are first Negative and then Positive
- Permutation of first N positive integers such that prime numbers are at prime indices
- Permutation of first N positive integers such that prime numbers are at prime indices | Set 2
- Minimum decrements to make integer A divisible by integer B
- Digital Root (repeated digital sum) of square of an integer using Digital root of the given integer