高精度,用 Python 秒了
AC代码
from math import *
t = int(input())
for _ in range(t):
n, a = input().split()
s = str(factorial(int(n)))
cnt = 0
for i in s:
if i == a:
cnt += 1
print(cnt)
为了尊重下传统语言C++,我还是重新写了一遍
说明:OJ不能提交不怪我啊
#include <iostream>
using namespace std;
int ans[1005][10] = {
{
0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
{
0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
{
0, 0, 1, 0, 0, 0, 0, 0, 0, 0 },
{
0, 0, 0, 0, 0, 0, 1, 0, 0, 0 },
{
0, 0, 1, 0, 1, 0, 0, 0, 0, 0 },
{
1, 1, 1, 0, 0, 0, 0, 0, 0, 0 },
{
1, 0, 1, 0, 0, 0, 0, 1, 0, 0 },
{
2, 0, 0, 0, 1, 1, 0, 0, 0, 0 },
{
2, 0, 1, 1, 1, 0, 0, 0, 0, 0 },
{
1, 0, 1, 1, 0, 0, 1, 0, 2, 0 },
{
2, 0, 1, 1, 0, 0, 1, 0, 2, 0 },
{
2, 1, 0, 1, 0, 0, 1, 0, 1, 2 },
{
4, 1, 0, 0, 1, 0, 1, 1, 0, 1 },
{
4, 0, 3, 0, 0, 0, 1, 1, 1, 0 },
{
2, 2, 2, 0, 0, 0, 0, 2, 2, 1 },
{
4, 1, 0, 2, 1, 0, 2, 2, 1, 0 },
{
4, 0, 3, 0, 0, 0, 0, 1, 4, 2 },
{
4, 0, 1, 1, 1, 2, 2, 1, 2, 1 },
{
5, 0, 2, 2, 1, 1, 1, 3, 1, 0 },
{
6, 3, 2, 1, 2, 1, 1, 0, 2, 0 },
{
7, 1, 3, 1, 2, 0, 2, 1, 1, 1 },
{
7, 3, 1, 0, 3, 1, 0, 2, 0, 3 },
{
8, 2, 2, 0, 1, 0, 2, 6, 1, 0 },
{
5, 1, 2, 1, 2, 2, 3, 2, 4, 1 },
{
6, 1, 2, 5, 4, 0, 2, 1, 1, 2 },
{
9, 4, 1, 3, 2, 3, 0, 0, 2, 2 },
{
8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 7, 9, 4, 8, 6, 7, 4, 7, 5 },
{
17, 10, 10, 5, 8, 5, 4, 4, 10, 6 },
{
19, 6, 6, 8, 7, 5, 6, 7, 9, 8 },
{
19, 8, 9, 8, 10, 3, 8, 7, 4, 6 },
{
26, 3, 10, 4, 4, 7, 6, 6, 11, 7 },
{
20, 8, 13, 8, 4, 6, 6, 8, 7, 6 },
{
21, 9, 8, 5, 8, 4, 11, 8, 7, 7 },
{
20, 12, 6, 9, 10, 7, 6, 3, 12, 5 },
{
20, 5, 11, 7, 8, 10, 8, 9, 7, 6 },
{
23, 5, 8, 7, 16, 3, 8, 8, 9, 6 },
{
22, 8, 8, 6, 10, 7, 11, 6, 9, 8 },
{
25, 11, 8, 9, 7, 8, 6, 8, 7, 8 },
{
21, 9, 14, 10, 13, 5, 4, 8, 8, 7 },
{
20, 7, 7, 5, 6, 10, 11, 9, 14, 12 },
{
25, 6, 8, 7, 5, 7, 11, 10, 18, 5 },
{
23, 6, 10, 8, 10, 3, 10, 12, 15, 7 },
{
35, 16, 8, 6, 7, 7, 6, 7, 9, 5 },
{
23, 13, 14, 10, 7, 13, 5, 7, 9, 7 },
{
25, 9, 9, 7, 13, 9, 9, 9, 10, 10 },
{
24, 7, 12, 11, 11, 10, 8, 9, 8, 12 },
{
32, 7, 10, 7, 11, 6, 9, 7, 18, 7 },
{
25, 11, 16, 9, 10, 9, 8, 10, 12, 6 },
{
29, 15, 8, 10, 4, 7, 11, 10, 14, 9 },
{
27, 8, 12, 8, 13, 14, 10, 9, 13, 5 },
{
27, 9, 9, 8, 13, 13, 8, 14, 8, 12 },
{
28, 13, 5, 15, 16, 1, 11, 11, 10, 13 },
{
30, 10, 9, 10, 10, 12, 12, 12, 8, 12 },
{
27, 15, 12, 13, 8, 8, 13, 9, 12, 10 },
{
36, 13, 14, 8, 15, 13, 9, 7, 5, 9 },
{
28, 8, 17, 10, 14, 13, 11, 13, 8, 9 },
{
27, 14, 16, 13, 10, 11, 7, 17, 8, 10 },
{
28, 14, 12, 8, 18, 10, 12, 2, 18, 13 },
{
34, 12, 9, 12, 6, 10, 15, 11, 10, 18 },
{
28, 11, 10, 10, 13, 12, 15, 12, 14, 14 },
{
29, 12, 8, 6, 12, 17, 17, 19, 9, 12 },
{
29, 13, 8, 18, 17, 17, 8, 15, 11, 7 },
{
32, 16, 17, 12, 12, 14, 11, 12, 12, 7 },
{
37, 11, 11, 12, 12, 15, 16, 10, 16, 7 },
{
32, 8, 19, 15, 12, 12, 11, 15, 10, 15 },
{
36, 9, 7, 9, 16, 11, 11, 15, 16, 20 },
{
26, 17, 13, 12, 11, 11, 13, 16, 17, 16 },
{
35, 6, 16, 10, 16, 9, 14, 19, 16, 13 },
{
28, 15, 19, 10, 10, 14, 19, 7, 14, 20 },
{
30, 15, 19, 10, 10, 14, 19, 7, 14, 20 },
{
35, 10, 14, 18, 14, 13, 14, 12, 12, 18 },
{
37, 12, 9, 12, 17, 27, 16, 6, 11, 15 },
{
36, 16, 17, 11, 18, 15, 11, 9, 17, 14 },
{
33, 13, 13, 12, 16, 14, 11, 25, 18, 12 },
{
45, 11, 14, 16, 11, 11, 15, 15, 12, 19 },
{
36, 11, 19, 20, 22, 8, 15, 15, 18, 7 },
{
42, 19, 15, 22, 11, 17, 14, 10, 11, 12 },
{
41, 17, 12, 16, 17, 15, 12, 12, 19, 14 },
{
39, 13, 21, 23, 17, 10, 8, 15, 17, 14 },
{
38, 18, 23, 13, 18, 13, 12, 19, 13, 12 },
{
39, 17, 12, 15, 18, 20, 19, 19, 10, 12 },
{
38, 10, 17, 17, 15, 15, 14, 22, 18, 17 },
{
35, 26, 24, 14, 15, 14, 17, 15, 12, 13 },
{
47, 19, 16, 19, 19, 18, 11, 8, 18, 12 },
{
51, 19, 18, 18, 12, 21, 9, 12, 13, 16 },
{
44, 23, 14, 18, 8, 16, 19, 13, 17, 19 },
{
47, 15, 14, 14, 25, 11, 21, 14, 14, 18 },
{
40, 13, 24, 21, 17, 14, 17, 13, 23, 13 },
{
42, 16, 11, 18, 29, 17, 12, 20, 19, 13 },
{
45, 19, 15, 16, 15, 21, 16, 11, 21, 20 },
{
47, 15, 20, 17, 18, 11, 18, 23, 16, 16 },
{
52, 14, 19, 15, 24, 18, 15, 18, 13, 15 },
{
42, 25, 24, 16, 15, 16, 21, 14, 17, 16 },
{
53, 25, 12, 11, 22, 20, 21, 17, 11, 16 },
{
47, 16, 11, 20, 16, 24, 16, 19, 25, 16 },
{
52, 19, 15, 22, 16, 15, 13, 25, 21, 14 },
{
54, 14, 17, 13, 11, 14, 25, 29, 14, 23 },
{
50, 11, 21, 21, 18, 25, 21, 18, 16, 15 },
{
48, 22, 23, 17, 20, 14, 23, 14, 19, 18 },
{
51, 14, 21, 14, 23, 24, 16, 20, 15, 22 },
{
46, 16, 15, 17, 21, 19, 26, 21, 21, 20 },
{
54, 20, 19, 14, 19, 15, 27, 18, 17, 22 },
{
61, 22, 17, 15, 12, 21, 17, 21, 26, 15 },
{
56, 21, 19, 22, 27, 12, 15, 14, 22, 21 },
{
57, 20, 18, 23, 25, 21, 19, 19, 19, 10 },
{
53, 24, 24, 16, 19, 22, 18, 19, 25, 13 },
{
49, 19, 28, 23, 13, 16, 18, 25, 28, 16 },
{
54, 19, 20, 15, 21, 16, 23, 22, 29, 18 },
{
57, 24, 14, 15, 14, 19, 27, 16, 18, 35 },
{
60, 24, 11, 17, 20, 20, 21, 24, 22, 23 },
{
53, 26, 24, 15, 18, 18, 16, 29, 22, 23 },
{
56, 20, 20, 12, 22, 14, 20, 29, 28, 25 },
{
53, 28, 13, 26, 23, 26, 25, 17, 20, 17 },
{
58, 16, 18, 26, 20, 19, 16, 27, 23, 27 },
{
57, 27, 21, 16, 25, 21, 19, 20, 18, 28 },
{
57, 22, 27, 16, 18, 22, 20, 20, 26, 27 },
{
57, 27, 28, 20, 20, 23, 19, 21, 23, 19 },
{
50, 25, 23, 26, 23, 26, 21, 24, 26, 15 },
{
52, 10, 25, 28, 23, 25, 21, 22, 29, 26 },
{
51, 20, 25, 19, 30, 32, 21, 22, 21, 22 },
{
60, 27, 26, 24, 21, 21, 19, 20, 27, 20 },
{
61, 24, 20, 30, 21, 29, 23, 26, 19, 15 },
{
62, 31, 20, 28, 21, 19, 29, 15, 19, 26 },
{
68, 22, 18, 18, 24, 22, 28, 22, 28, 22 },
{
57, 24, 24, 30, 27, 20, 27, 24, 16, 25 },
{
62, 22, 24, 24, 18, 24, 28, 24, 22, 28 },
{
54, 22, 28, 21, 26, 30, 23, 30, 23, 22 },
{
60, 25, 19, 31, 22, 20, 23, 24, 29, 28 },
{
59, 28, 30, 26, 20, 22, 29, 16, 30, 23 },
{
63, 29, 24, 27, 24, 19, 22, 23, 21, 33 },
{
66, 23, 26, 19, 30, 25, 15, 26, 28, 29 },
{
70, 26, 29, 19, 25, 20, 17, 25, 24, 35 },
{
68, 24, 27, 23, 22, 23, 30, 26, 19, 30 },
{
63, 28, 37, 24, 22, 21, 26, 27, 28, 18 },
{
68, 25, 22, 26, 32, 33, 23, 22, 21, 24 },
{
66, 26, 24, 25, 20, 23, 35, 27, 23, 29 },
{
70, 42, 23, 19, 29, 24, 22, 25, 22, 25 },
{
63, 28, 25, 21, 29, 29, 35, 27, 27, 19 },
{
70, 28, 24, 20, 29, 28, 25, 26, 31, 24 },
{
68, 29, 31, 20, 22, 32, 31, 26, 20, 28 },
{
66, 32, 25, 21, 22, 30, 27, 26, 34, 27 },
{
73, 27, 20, 32, 22, 30, 23, 31, 27, 27 },
{
66, 22, 40, 30, 26, 24, 29, 28, 21, 28 },
{
67, 23, 34, 30, 22, 30, 40, 22, 30, 18 },
{
72, 27, 23, 32, 28, 18, 48, 19, 27, 25 },
{
75, 34, 22, 33, 24, 28, 21, 22, 36, 26 },
{
70, 19, 30, 38, 27, 29, 20, 30, 38, 22 },
{
60, 32, 31, 24, 21, 25, 34, 29, 35, 34 },
{
74, 26, 28, 32, 34, 18, 32, 34, 24, 26 },
{
75, 30, 16, 39, 27, 26, 32, 20, 29, 36 },
{
66, 27, 31, 36, 31, 22, 35, 20, 34, 30 },
{
79, 31, 23, 26, 36, 22, 30, 29, 27, 31 },
{
69, 25, 37, 37, 32, 21, 25, 37, 24, 30 },
{
75, 18, 40, 27, 36, 29, 28, 27, 33, 26 },
{
81, 33, 31, 21, 33, 34, 29, 29, 27, 23 },
{
83, 27, 31, 32, 26, 25, 34, 27, 33, 25 },
{
67, 28, 37, 33, 27, 32, 31, 36, 25, 30 },
{
73, 32, 22, 24, 39, 33, 27, 34, 23, 41 },
{
72, 34, 28, 32, 31, 26, 36, 30, 29, 32 },
{
74, 27, 35, 29, 40, 36, 33, 24, 26, 28 },
{
82, 23, 32, 29, 27, 30, 35, 27, 39, 31 },
{
80, 27, 26, 35, 32, 39, 29, 27, 24, 38 },
{
70, 30, 32, 42, 24, 35, 18, 41, 31, 36 },
{
87, 24, 40, 28, 31, 34, 21, 24, 38, 35 },
{
81, 29, 33, 31, 30, 39, 36, 24, 23, 38 },
{
80, 37, 36, 28, 26, 23, 36, 36, 34, 30 },
{
76, 21, 29, 39, 34, 31, 40, 37, 32, 30 },
{
80, 33, 41, 29, 35, 38, 30, 25, 32, 28 },
{
71, 53, 36, 30, 25, 29, 42, 24,