Given and . The task is to find a N digits number which is divisible by D ( 2 <= D <= 10). If it is not possible then print Impossible.

**Examples**:

Input :N = 2 and D = 2Output :20Input :N = 1 and D = 10Output :Impossible

**Approach:** There are two conditions D=10 and D not equals 10. Id D = 10 and N = 1 then only answer is not possible and in all other conditions, the answer will be possible.

1. If D is 10, Print 1 followed by n-1 times zero. 2. If D is not 10 Print D followed by n-1 times zero

Below is the implementation of the above approach:

## C++

`// CPP program to Find N digits ` `// number which is divisible by D ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to return N digits ` `// number which is divisible by D ` `string findNumber(` `int` `n, ` `int` `d) ` `{ ` ` ` `// to store answer ` ` ` `string ans = ` `""` `; ` ` ` ` ` `if` `(d != 10) { ` ` ` `ans += to_string(d); ` ` ` `for` `(` `int` `i = 1; i < n; i++) ` ` ` `ans += ` `'0'` `; ` ` ` `} ` ` ` `else` `{ ` ` ` `if` `(n == 1) ` ` ` `ans += ` `"Impossible"` `; ` ` ` `else` `{ ` ` ` `ans += ` `'1'` `; ` ` ` `for` `(` `int` `i = 1; i < n; i++) ` ` ` `ans += ` `'0'` `; ` ` ` `} ` ` ` `} ` ` ` ` ` `return` `ans; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `n = 12, d = 3; ` ` ` ` ` `cout << findNumber(n, d); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to Find N digits ` `// number which is divisible by D ` ` ` `import` `java.io.*; ` ` ` `class` `GFG { ` ` ` ` ` `// Function to return N digits ` `// number which is divisible by D ` `static` `String findNumber(` `int` `n, ` `int` `d) ` `{ ` ` ` `// to store answer ` ` ` `String ans = ` `""` `; ` ` ` ` ` `if` `(d != ` `10` `) { ` ` ` `ans += Integer.toString(d); ` ` ` `for` `(` `int` `i = ` `1` `; i < n; i++) ` ` ` `ans += ` `'0'` `; ` ` ` `} ` ` ` `else` `{ ` ` ` `if` `(n == ` `1` `) ` ` ` `ans += ` `"Impossible"` `; ` ` ` `else` `{ ` ` ` `ans += ` `'1'` `; ` ` ` `for` `(` `int` `i = ` `1` `; i < n; i++) ` ` ` `ans += ` `'0'` `; ` ` ` `} ` ` ` `} ` ` ` ` ` `return` `ans; ` `} ` ` ` `// Driver code ` ` ` ` ` `public` `static` `void` `main (String[] args) { ` ` ` `int` `n = ` `12` `, d = ` `3` `; ` ` ` ` ` `System.out.println(findNumber(n, d)); ` ` ` `} ` `} ` `// This code is contributed by anuj_67.. ` |

*chevron_right*

*filter_none*

## Python 3

`# Python 3 program to Find N digits ` `# number which is divisible by D ` ` ` `# Function to return N digits ` `# number which is divisible by D ` `def` `findNumber(n, d): ` ` ` ` ` `# to store answer ` ` ` `ans ` `=` `"" ` ` ` ` ` `if` `(d !` `=` `10` `) : ` ` ` `ans ` `+` `=` `str` `(d) ` ` ` `for` `i ` `in` `range` `(` `1` `,n): ` ` ` `ans ` `+` `=` `'0'` ` ` `else` `: ` ` ` `if` `(n ` `=` `=` `1` `): ` ` ` `ans ` `+` `=` `"Impossible"` ` ` `else` `: ` ` ` `ans ` `+` `=` `'1'` ` ` `for` `i ` `in` `range` `(` `1` `,n): ` ` ` `ans ` `+` `=` `'0'` ` ` ` ` `return` `ans ` ` ` `# Driver code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` `n ` `=` `12` ` ` `d ` `=` `3` ` ` ` ` `print` `(findNumber(n, d)) ` ` ` `# This code is contributed by ` `# ChitraNayal ` |

*chevron_right*

*filter_none*

## C#

`// C# program to Find N digits ` `// number which is divisible by D ` `using` `System; ` ` ` `class` `GFG { ` ` ` `// Function to return N digits ` `// number which is divisible by D ` `static` `string` `findNumber(` `int` `n, ` `int` `d) ` `{ ` ` ` ` ` `// to store answer ` ` ` `string` `ans = ` `""` `; ` ` ` ` ` `if` `(d != 10) { ` ` ` ` ` `ans += d.ToString(); ` ` ` ` ` `for` `(` `int` `i = 1; i < n; i++) ` ` ` `ans += ` `'0'` `; ` ` ` `} ` ` ` ` ` `else` `{ ` ` ` ` ` `if` `(n == 1) ` ` ` `ans += ` `"Impossible"` `; ` ` ` ` ` `else` `{ ` ` ` ` ` `ans += ` `'1'` `; ` ` ` `for` `(` `int` `i = 1; i < n; i++) ` ` ` `ans += ` `'0'` `; ` ` ` `} ` ` ` `} ` ` ` ` ` `return` `ans; ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main () ` `{ ` ` ` ` ` `int` `n = 12, d = 3; ` ` ` `Console.WriteLine(findNumber(n, d)); ` `} ` `} ` ` ` `// This code is contributed by Subhadeep ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to Find N digits ` `// number which is divisible by D ` ` ` `// Function to return N digits ` `// number which is divisible by D ` `function` `findNumber(` `$n` `, ` `$d` `) ` `{ ` ` ` `// to store answer ` ` ` `$ans` `= ` `""` `; ` ` ` ` ` `if` `(` `$d` `!= 10) ` ` ` `{ ` ` ` `$ans` `.= ` `strval` `(` `$d` `); ` ` ` `for` `(` `$i` `= 1; ` `$i` `< ` `$n` `; ` `$i` `++) ` ` ` `$ans` `.= ` `'0'` `; ` ` ` `} ` ` ` `else` ` ` `{ ` ` ` `if` `(n == 1) ` ` ` `$ans` `.= ` `"Impossible"` `; ` ` ` `else` ` ` `$ans` `.= ` `'1'` `; ` ` ` `for` `(` `$i` `= 1; ` `$i` `< ` `$n` `; ` `$i` `++) ` ` ` `$ans` `.= ` `'0'` `; ` ` ` `} ` ` ` ` ` `return` `$ans` `; ` `} ` ` ` `// Driver code ` `$n` `= 12; ` `$d` `= 3; ` ` ` `print` `(findNumber(` `$n` `, ` `$d` `)); ` ` ` `// This code is contributed by mits ` |

*chevron_right*

*filter_none*

**Output:**

300000000000

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Find a N-digit number such that it is not divisible by any of its digits
- Find a N-digit number such that it is not divisible by any of its digits
- Find N numbers such that a number and its reverse are divisible by sum of its digits
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Check if the sum of digits of number is divisible by all of its digits
- Smallest number with sum of digits as N and divisible by 10^N
- Largest number with the given set of N digits that is divisible by 2, 3 and 5
- Number of digits to be removed to make a number divisible by 3
- Check if N is divisible by a number which is composed of the digits from the set {A, B}
- Check whether sum of digits at odd places of a number is divisible by K
- Number of integers in a range [L, R] which are divisible by exactly K of it's digits
- Program to check if a number is divisible by sum of its digits
- Possible to make a divisible by 3 number using all digits in an array
- Program to check if a number is divisible by any of its digits
- Check whether product of digits at even places of a number is divisible by K
- Smallest number greater than or equal to X whose sum of digits is divisible by Y
- Given a large number, check if a subsequence of digits is divisible by 8
- Smallest N digit number divisible by all possible prime digits
- Check if the number formed by the last digits of N numbers is divisible by 10 or not

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.