Codeforces Round 235 (Div. 2)
D
Roman and Numbers
Codeforces
2000
原题
← CE →
翻译中…

Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number $*n*$, modulo $*m*$.

翻译中…

Number $*x*$ is considered close to number $*n*$ modulo $*m*$, if:

翻译中…
  • it can be obtained by rearranging the digits of number $*n*$,
  • it doesn't have any leading zeroes,
  • the remainder after dividing number $*x*$ by $*m*$ equals 0.
翻译中…

Roman is a good mathematician, but the number of such numbers is too huge for him. So he asks you to help him.

翻译中…

Input

翻译中…

The first line contains two integers: $*n*$ $(1 ≤ *n* < 10^{18})$ and $*m*$ $(1 ≤ *m* ≤ 100)$.

翻译中…

Output

翻译中…

In a single line print a single integer — the number of numbers close to number $*n*$ modulo $*m*$.

翻译中…

Note

翻译中…

In the first sample the required numbers are: 104, 140, 410.

翻译中…

In the second sample the required number is 232.

翻译中…

样例

Input #1
104 2
Output #1
3
InputCopy OutputCopy
Input #2
223 4
Output #2
1
InputCopy OutputCopy
Input #3
7067678 8
Output #3
47
InputCopy OutputCopy
题目信息
题号
401D
时间限制
4 s
内存限制
512 MB
标签
位运算
暴力
组合数学
动态规划
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。