Given four integers x, y, z and n, the task is to find the largest n digit number which is divisible by x, y and z.
Input: x = 2, y = 3, z = 5, n = 4
9990 is the largest 4-digit number which is divisible by 2, 3 and 5.
Input: x = 3, y = 23, z = 6, n = 2
Output: Not possible
- Find the largest n digit number i.e. pow(10, n) – 1 and store it in a variable largestN.
- Find LCM of the given three numbers x, y and z say LCM.
- Calculate the remainder when largestN is divided by LCM i.e. largestN % LCM and store it in a variable remainder.
- Subtract remainder from largestN. If the result is still an n digit number then print the result.
- Else print Not possible.
Below is the implementation of the above approach:
- Largest K digit number divisible by X
- C++ Program for Largest K digit number divisible by X
- Java Program for Largest K digit number divisible by X
- Sum of n digit numbers divisible by a given number
- Count n digit numbers divisible by given number
- Smallest n digit number divisible by given three numbers
- Largest Even and Odd N-digit numbers in Octal Number System
- Largest Even and Odd N-digit numbers in Hexadecimal Number System
- Largest number less than N with digit sum greater than the digit sum of N
- Largest Even and Odd N-digit numbers
- N digit numbers divisible by 5 formed from the M digits
- Largest Even and Odd N-digit numbers of base B
- Smallest and Largest sum of two n-digit numbers
- Largest and Smallest N-digit Octal Numbers
- 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.