- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Suppose we have two numbers N and D. We have to find N digit number, that is divisible by D. If N is 3, and D is 5, then the number can be 500. This can be solved easily. If D is 10 and N is 1, then it will be impossible. We can put D, and suppose the D has m number of digits, then attach N – m number of 0s to make it N digit number and divisible by D.

#include<iostream> using namespace std; string nDigitDivByD(int n, int d) { string ans = ""; if (d < 10) { ans += to_string(d); for (int i = 1; i < n; i++) ans += "0"; } else { if (n == 1) return "Cannot find any number"; else { string temp = to_string(d); ans += to_string(d); for (int i = 0; i < n-temp.length(); i++) ans += "0"; } } return ans; } int main() { int n = 5, d = 15; cout << nDigitDivByD(n, d); }

15000

- Related Questions & Answers
- Find permutation of n which is divisible by 3 but not divisible by 6 in C++
- Sum which is divisible by n in JavaScript
- Check if N is divisible by a number which is composed of the digits from the set {A, B} in Python
- Count digits in given number N which divide N in C++
- Find the number closest to n and divisible by m in C++
- Find elements of an array which are divisible by N using STL in C++
- Find the Number which contain the digit d in C++
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M in C++
- Largest number with the given set of N digits that is divisible by 2, 3 and 5 in C++
- Count n digit numbers divisible by given number in C++
- C# Program to find whether the Number is Divisible by 2
- Generating a random number that is divisible by n in JavaScript
- Smallest number that is divisible by first n numbers in JavaScript
- N digit numbers divisible by 5 formed from the M digits in C++
- C Program to check if a number is divisible by sum of its digits

Advertisements