题目传送门
#include <bits/stdc++.h>
using namespace std;
//高精度乘法模板
vector<int> mul(vector<int> &A, int b) {
vector<int> C;
int t = 0;
for (int i = 0; i < A.size() || t; i++) {
if (i < A.size()) t += A[i] * b;
C.push_back(t % 10);
t /= 10;
}
while (C.size() > 1 && C.back() == 0) C.pop_back();
return C;
}
int main() {
int t;
cin >> t;
for (int i = 1; i <= t; i++) {
int n, a;
cin >> n >> a;
vector<int> A;
int cnt = 0;
//倒着放的噢~
A.push_back(1);
for (int j = 2; j <= n; j++) A = mul(A, j);
//这个求a出现的次数,就是一个暴力求全部!
for (int j = 0; j < A.size(); j++)
if (A[j] == a) cnt++;
cout << cnt << endl;
}
return 0;
}