C++ Program for Largest 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 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 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. CPP // CPP code to find highest 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 MAX int MAX = pow(10, K) - 1; // returning ans return (MAX - (MAX % X)); } // Driver int main() { // Number whose divisible is to be found int X = 30; // Max K-digit divisible is to be found int K = 3; cout << answer(X, K); } Output: 990 Please refer complete article on Largest K digit number divisible by X for more details! Comment More infoAdvertise with us Next Article C++ Program for Largest K digit number divisible by X kartik Follow Improve Article Tags : Mathematical C++ Programs DSA Practice Tags : Mathematical Similar Reads C++ Program for Smallest K digit number divisible by X 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 num 2 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 Largest and smallest digit of a number Given a number N. The task is to find the largest and the smallest digit of the number.Examples : Input : N = 2346 Output : 6 2 6 is the largest digit and 2 is smallestInput : N = 5 Output : 5 5 Approach: An efficient approach is to find all digits in the given number and find the largest and the sm 7 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 Sum of M maximum distinct digit sum from 1 to N that are factors of K Given an array of natural numbers upto N and two numbers M and K, the task is to find the sum of M maximum distinct digit sum M numbers from N natural numbers which are factors of K. Examples: Input: N = 50, M = 4, K = 30 Output: 16 Explanation: From 1 to 50, factors of 30 = {1, 2, 3, 5, 6, 10, 15, 11 min read Like