Two integers n and k are given. Our task is to print K-rounding of n. K-rounding is the minimum positive integer X, such that x ends with k or more zeros and is divisible by n.
Input : n = 30, k = 3. Output : 3000 3000 is the smallest number that has at-least k 0s and is divisible by n. Input : n = 375, k = 4. Output : 30000
Method 1 :
The brute force approach is to start with result = 10k. Check if result is divided by n. If yes, it’s the answer, else increase it by 10k
Method 2 : The efficient approach is to calculate the LCM of 10k and n.
Suppose, n = 375, k = 4.
result = 10000.
Now, LCM of 375 and 10000 is the lowest number divided by both of them.
It will contain k or more zeros (because it is multiple of 10k) and will be a multiple of n as well.
Below is the implementation :
This article is contributed by Rohit Thapliyal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Find the smallest number X such that X! contains at least Y trailing zeros.
- Count number of trailing zeros in (1^1)*(2^2)*(3^3)*(4^4)*..
- Count number of trailing zeros in product of array
- Count number of trailing zeros in Binary representation of a number using Bitset
- Smallest number with at least n trailing zeroes in factorial
- Count unique numbers that can be generated from N by adding one and removing trailing zeros
- Prove that atleast one of three consecutive even numbers is divisible by 6
- Smallest number divisible by first n numbers
- Smallest number with sum of digits as N and divisible by 10^N
- Smallest K digit number divisible by X
- Smallest number greater than or equal to N divisible by K
- Find Nth smallest number that is divisible by 100 exactly K times
- Length of the smallest number which is divisible by K and formed by using 1's only
- Smallest n digit number divisible by given three numbers
- C++ Program for Smallest K digit number divisible by X