Given two numbers N and K . The task is to find N’th smallest number that is divided by 100 exactly K times.
Input : N = 12, K = 2
Output : 120000
120000 is divisible by 100 exactly 2 times and
is the 12 th smallest number also.
Input : N = 1000, K = 2
Output : 10010000
- First find the smallest number that is divisible by 100 exactly K times. That is 2*K 0’s after 1 as 100 has two 0’s only.
- To find N’th smallest number, multiply N with the previous number we get after adding 2*k 0’s.
- Consider a case when N is divisible by 100 as if we multiply N with the previous number then the new number will have more than (2*k + 1) trailing 0’s that means it will divisible by 100 more than K times.
- Multiply that number with (N + 1). Use string as N and K can be very large that will not fit in integer limit.
Below is the implementation of above approach:
Time Complexity: O(K)
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Number formed after K times repeated addition of smallest divisor of N
- Smallest N digit number divisible by N
- 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
- C++ Program for Smallest K digit number divisible by X
- Smallest number divisible by n and has at-least k trailing zeros
- Smallest number greater than or equal to N divisible by K
- 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
- Java Program for Smallest K digit number divisible by X
- Smallest number greater than or equal to X whose sum of digits is divisible by Y
- Find the maximum difference after applying the given operations two times on a number
- Find smallest possible Number from a given large Number with same count of digits
- Find the smallest number whose digits multiply to a given number n
- Find the Kth number which is not divisible by N
- Find smallest number K such that K % p = 0 and q % K = 0
- Find K'th smallest number such that A + B = A | B
- Find if a number is divisible by every number in a list
- Find nth number that contains the digit k or divisible by k.
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.