Given a number N, the task is to find the largest N-digit multiple of N.
Input: N = 2
98 is the largest multiple of 2 and is of 2 digits.
Input: N = 3
999 is the largest multiple of 3 and is of 3 digits.
Approach: The idea is to make an observation.
- If we observe carefully, a series will be formed as 9, 98, 999, 9996, 99995, …
- In the above series, the N-th term can be calculated as:
- Therefore, the number N is taken as the input and the above formula is implemented.
Below is the implementation of the above approach:
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.
- Find the largest possible k-multiple set
- Find the largest multiple of 2, 3 and 5
- Find the largest multiple of 3 from array of digits | Set 2 (In O(n) time and O(1) space)
- Find the Largest N digit perfect square number in Base B
- Largest number less than N with digit sum greater than the digit sum of N
- Nth number whose sum of digit is multiple of 10
- Smallest integer with digit sum M and multiple of N
- Smallest N digit number which is a multiple of 5
- Find the remainder when First digit of a number is divided by its Last digit
- Largest Even and Odd N-digit numbers
- Product of N with its largest odd digit
- Largest and smallest digit of a number
- Largest K digit number divisible by X
- Largest Even and Odd N-digit numbers of base B
- Largest value of x such that axx is N-digit number of base b
- Largest N digit number in Base B
- Largest even digit number not greater than N
- Smallest and Largest sum of two n-digit numbers
- Smallest and Largest N-digit perfect squares
- Largest palindrome which is product of two n-digit numbers
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.