P1591 阶乘数码

原题链接 https://www.luogu.com.cn/problem/P1591

题目描述

统计指定数码 a 在 n 的阶乘的十进制表示中出现了多少次。

输入 第一行是数据组数 t,随后 t 行各给出一个正整数 n 和一个数码 a。

输出 每组输出一行,给出 a 出现的次数。

输入输出样例

输入

2
5 2
7 0

输出

1
2

题解

from math import factorial
t=int(input())
for i in range(t):
    n,a=map(int,input().split())
    print(str(factorial(n)).count(str(a)))