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 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 find largest number in a list
- Python program to find second largest number in a list
- Program to print all the numbers divisible by 3 and 5 for a given number
- Python Program to print digit pattern
- Python program to find tuples which have all elements divisible by K from a list of tuples
- Python program to find N largest elements from a list
- Python Program to find largest element in an array
- Python Program for Largest Sum Contiguous Subarray
- Python - Match Kth number digit in list elements
- Python | Largest number possible from list of given numbers
- Python Program for Efficient program to print all prime factors of a given number
- Python | Find longest consecutive letter and digit substring
- Python - Convert Float to digit list
- Python - Test rear digit match in all list elements
- Python | Merge adjacent Digit characters
- Python | Check if front digit is Odd in list
- Python - Test if all digits starts from % K digit