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
- Smallest n digit number divisible by given three numbers
- Count n digit numbers divisible by given number
- Largest Even and Odd N-digit numbers in Octal 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
- Smallest and Largest sum of two n-digit numbers
- Largest palindrome which is product of two n-digit numbers
- Count of Numbers in Range where first digit is equal to last digit of the number
- Smallest K digit number divisible by X
- 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.