已注销CwUB!E6V @ 2022-03-28 20:50:48
#include<iostream>
#include<math.h>
using namespace std;
void fun(int n,int t)
{
int i, j, k;
int flag = 0;
double len = 0;
int a[1001] = { 0 }, b[1001] = { 0 };
for (i = 0; i < n; i++)
a[i] = i + 1;
b[0] = a[n - 1] * a[n - 2];
if (b[0] > 9)
{
b[1] += b[0] / 10;
b[0] = b[0] % 10;
}
for (i = 0; i <= n - 3; i++)
{
for (j = 0; j <= i + 1; j++)
b[j] *= a[n - 3 - i];
for (k = 0; k <= j; k++)
if (b[k] > 9)
{
b[k + 1] += b[k] / 10;
b[k] = b[k] % 10;
}
}
for (i = 1; i <= n; i++)
len += log10(i);
//len++;
for (i = 0; i < (int)len + 1; i++)
if (b[i] == t)
flag++;
cout << flag<<endl;
}
int main()
{
int i, num;
int n[11], t[11];
cin >> num;
for (i = 0; i < num; i++)
{
cin >> n[i] >> t[i];
}
for(i=0;i<num;i++)
fun(n[i], t[i]);
return 0;
}