Python Program for Smallest K digit number divisible by X Last Updated : 14 Mar, 2023 Comments Improve Suggest changes Like Article Like Report Integers X and K are given. The task is to find smallest K-digit number divisible by X. Examples: Input : X = 83, K = 5 Output : 10043 10040 is the smallest 5 digit number that is multiple of 83. Input : X = 5, K = 2 Output : 10 An efficient solution would be : Compute MIN : smallest K-digit number (1000...K-times) If, MIN % X is 0, ans = MIN else, ans = (MIN + X) - ((MIN + X) % X)) This is because there will be a number in range [MIN...MIN+X] divisible by X. Python3 # Python code to find smallest K-digit # number divisible by X def answer(X, K): # Computing MAX MIN = pow(10, K-1) if(MIN%X == 0): return (MIN) else: return ((MIN + X) - ((MIN + X) % X)) X = 83; K = 5; print(answer(X, K)); # Code contributed by Mohit Gupta_OMG <(0_o)> Output : 10043 Time Complexity: O(logk) Auxiliary Space: O(1) Please refer complete article on Smallest K digit number divisible by X for more details! Comment More infoAdvertise with us Next Article Python Program for Smallest K digit number divisible by X K kartik Follow Improve Article Tags : Python Programs DSA Similar Reads Python Program to Find Numbers Divisible by Another Number We are given a list of numbers and a number. We have to find all the numbers in the list that are divisible by the given single number. Examples:Input: list=[8, 14, 21, 36, 43], num=3Output: 21, 36, 57Input: list=[2, 17, 25, 31, 48, 55], num=5Output: 25, 55In this article, we will discuss the differ 3 min read Python Program for Check if all digits of a number divide it Given a number n, find whether all digits of n divide it or not. Examples: Input : 128Output : Yes128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0. Input : 130Output : No We want to test whether each digit is non-zero and divides the number. For example, with 128, we want to test d != 0 && 128 % 3 min read Sum the Digits of a Given Number - Python The task of summing the digits of a given number in Python involves extracting each digit and computing their total . For example, given the number 12345, the sum of its digits is 1 + 2 + 3 + 4 + 5 = 15. Using modulo (%)This method efficiently extracts each digit using the modulus (%) and integer di 2 min read Python3 Program to Count rotations which are divisible by 10 Given a number N, the task is to count all the rotations of the given number which are divisible by 10.Examples: Input: N = 10203 Output: 2 Explanation: There are 5 rotations possible for the given number. They are: 02031, 20310, 03102, 31020, 10203 Out of these rotations, only 20310 and 31020 are d 2 min read Python - Split Numeric String into K digit integers Given a String, convert it to K digit integers Input : test_str = '457336', K = 2 Output : [45, 73, 36] Explanation : Divided in 2 digit integers. Input : test_str = '457336', K = 3 Output : [457, 336] Explanation : Divided in 3 digit integers. Method #1 : Using int() + slice + loop In this, we iter 5 min read Like