First K Digits
Easy Accuracy: 0.0% Submissions: 2 Points: 2

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. 

Example 1:

Input: n = 3, k = 3
Output: 333
Explanation: 1/3=0.33333, so
after point 3 digits are 3,3,3.

​Example 2:

Input: n = 50, k = 4
Output: 0200
Explanation: 1/50=0.020000, so 
after point 4 digits are 0,2,0,0.

Your Task:  
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)

Constraints:
1 ≤ n, k ≤ 105

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.