题目传送门
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int a[N];
void mul(int a[], int b, int &len) {
int t = 0;
for (int i = 1; i <= len; i++) {
t += a[i] * b;
a[i] = t % 10;
t /= 10;
}
while (t) {
a[++len] = t % 10;
t /= 10;
}
//去前导0
while (len > 1 && !a[len]) len--;
}
int main() {
int T;
cin >> T;
while (T--) {
int n, x;
scanf("%d %d", &n, &x);
int al = 0, cnt = 0;
a[++al] = 1;
for (int i = 2; i <= n; i++) mul(a, i, al);
for (int i = 1; i <= al; i++)
if (a[i] == x) cnt++;
printf("%d\n", cnt);
}
return 0;
}