#P4163. [SCOI2007] 排列
[SCOI2007] 排列
Description
Given a digit string and a positive integer , count how many distinct permutations of are divisible by (leading is allowed). For example, has permutations divisible by , among which end with and end with .
Input Format
The first line contains an integer , the number of testdata. Each of the following lines contains and , separated by a space. String contains only digits .
Output Format
For each testdata, output one line containing the number of permutations divisible by .
7
000 1
001 1
1234567890 1
123434 2
1234 7
12345 17
12345678 29
1
3
3628800
90
3
6
1398
Hint
Constraints: For of the testdata, the length of does not exceed , , .
In the first three examples, the numbers of permutations are , and they are all multiples of .
Translated by ChatGPT 5
京公网安备 11011102002149号