Please enter your email address or userHandle.
Given a positive integer n, find first k digits after the decimal in the value of 1/n and return it as a string.
Note: Your program should avoid overflow and floating-point arithmetic.
Input: n = 3, k = 3
Explanation: 1/3=0.33333, so
after point 3 digits are 3,3,3.
Input: n = 50, k = 4
Explanation: 1/50=0.020000, so
after point 4 digits are 0,2,0,0.
You don't need to read input or print anything. Your task is to complete the function Kdigits() which takes n, k as inputs and returns the string.
Expected Time Complexity: O(k)
Expected Auxiliary Space: O(1)
1 ≤ n, k ≤ 105
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Login to access your submissions.
Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.