Integers X and K are given. The task is to find highest K-digit number divisible by X.
Input : X = 30, K = 3 Output : 990 990 is the largest three digit number divisible by 30. Input : X = 7, K = 2 Output : 98
An efficient solution is to use below formula.
ans = MAX - (MAX % X) where MAX is the largest K digit number which is 999...K-times
The formula works on simple school method division. We remove remainder to get the largest divisible number.
Please refer complete article on Largest K digit number divisible by X for more details!
- Python Program for Smallest K digit number divisible by X
- Python program to find largest number in a list
- Python program to find second largest number in a list
- Python Program to check whether it is possible to make a divisible by 3 number using all digits in an array
- Python Program for Find largest prime factor of a number
- Python Program to print digit pattern
- Python Program for Largest Sum Contiguous Subarray
- Python Program to find largest element in an array
- Python program to find N largest elements from a list
- Program to print all the numbers divisible by 3 and 5 for a given number
- Python | Largest number possible from list of given numbers
- Python Program for Efficient program to print all prime factors of a given number
- Python Program to Find the Number Occurring Odd Number of Times
- Python Program for How to check if a given number is Fibonacci number?
- Python Program for n-th Fibonacci number