C++ Program for Smallest K digit number divisible by X Last Updated : 05 Dec, 2018 Comments Improve Suggest changes Like Article Like Report Integers X and K are given. The task is to find the 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. CPP // CPP code to find smallest K-digit number // divisible by X #include <bits/stdc++.h> using namespace std; // Function to compute the result int answer(int X, int K) { // Computing MIN int MIN = pow(10, K - 1); // MIN is the result if (MIN % X == 0) return MIN; // returning ans return ((MIN + X) - ((MIN + X) % X)); } // Driver int main() { // Number whose divisible is to be found int X = 83; // Max K-digit divisible is to be found int K = 5; cout << answer(X, K); } Output: 10043 Please refer complete article on Smallest K digit number divisible by X for more details! Comment More infoAdvertise with us Next Article C++ Program for Smallest K digit number divisible by X K kartik Follow Improve Article Tags : Mathematical C++ Programs DSA Practice Tags : Mathematical Similar Reads C++ Program for Largest K digit number divisible by X Integers X and K are given. The task is to find highest K-digit number divisible by X. Examples: 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 i 1 min read Check if the square of a number is divisible by K or not Given two integers, X and K, the task is to find if X2 is divisible by K or not. Here, both K and X can lie in the range [1,1018]. Examples: Input: X = 6, K = 9 Output: YES Explanation: Since 62 is equal to 36, which is divisible by 9. Input: X = 7, K = 21 Output: NO Explanation: Since 72 is equal t 4 min read Smallest number greater than or equal to N using only digits 1 to K Given a number N and an integer K, the task is to find the smallest number greater than or equal to N, formed using only first K non-zero digits( 1, 2, ..., K-1, K).Examples: Input: N = 124, K = 3 Output: 131 Explanation: The smallest number greater than or equal to 124, which is only made of digits 9 min read Find N numbers such that a number and its reverse are divisible by sum of its digits Given a number N, the task is to print the first N numbers such that every number and the reverse of the number is divisible by its sum of digits.Example: Input: N = 4 Output: 1 2 3 4 Explanation: The reverse of every single digit number is the same number. And, every number is divisible by itself. 9 min read Find number formed in K steps by reducing N by 1 if last digit is 0 else divide by 10 Given two integers N and K. Perform the following type of operations on N: if the last digit of N is non-zero, decrease the number by one.if the last digit of N is zero, divide the number by 10 (i.e. remove the last digit). The task is to print the result after K such operations. Examples: Input: N 4 min read Like