Problem Statement | |||||||||||||
We define a permutation of an integer N as an integer that has the exact same digits as N, but possibly in a different order. Two permutations of N are considered different if the numbers they represent are not the same. For example, the set of all different permutations of the number N = 313 is {133, 313, 331}. Given a String N and an int M, determine the number of different permutations of N that are divisible by M. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
- | N will contain between 1 and 15 non-zero digits ('1'-'9'), inclusive. | ||||||||||||
- | M will be between 1 and 50, inclusive. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
| |||||||||||||
4) | |||||||||||||
|