
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
C++ Programming for Smallest K digit number divisible by X?
Smallest K digit number that divisible by X is found using the formula by checking divisible by X. The formula works in the following way −
Compute minimum K digit number [min] for example: 10/100/1000 etc.
Now find if min is divisible by X. if yes, then this is the answer.
If not, then min+X - ([min+X]%k) is the answer.
Example
#include <iostream> #include <math.h> using namespace std; int main() { int X = 83; int K = 5; cout<<"The smallest "<<K<<" digit number divisible by "<<X<<" is "; int MIN = pow(10, K - 1); if (MIN % X == 0) cout<<MIN; cout<<((MIN + X) - ((MIN + X) % X)); cout << answer(X, K); }
Output
The smallest 5 digit number divisible by 83 is 100430
- Related Articles
- C++ Program for Smallest K digit number divisible by X?
- Python Program for Smallest K digit number divisible by X
- Java Program for Smallest K digit number divisible by X
- C++ Program for Largest K digit number divisible by X?
- C++ Program for the Largest K digit number divisible by X?
- Largest K digit number divisible by X in C++
- Java Program for Largest K digit number divisible by X
- Find nth number that contains the digit k or divisible by k in C++
- Smallest Integer Divisible by K in Python
- Which is the smallest 4-digit number divisible by 8, 10 and 12?
- Find the smallest 5-digit number which is divisible by 12, 18, 30.
- Find the smallest 4-digit number which is divisible by 18,24 and 32 .
- Find the smallest 5 digit number which is exactly divisible by 20,25 and 30.
- Determine the smallest 3-digit number which is exactly divisible by 6,8 and 12.
- Find the smallest 4 digit number which is exactly divisible by 18, 24, 36.

Advertisements