C++30分样例没问题求助

P1591 阶乘数码

伏地魔老杨 @ 2022-09-22 13:03:40

#include <iostream>
#include <cstring>
using namespace std;
int mul[9000000];
void i2BIG(int n, int a[]) 
{
    int la = 0;
    while (n > 0)
    {
          la++;
          a[la] = n % 10;
          n /= 10;
    }
    if (la == 0) la++;
    a[0] = la;
}

void mulBIG(int x[], long long y, int z[])
{
    z[0] = x[0];
    for (int i = 1; i <= z[0]; i++) 
   p     z[i] = x[i] * y;
    for (int i = 1; i <= z[0]; i++) 
    {
        z[i + 1] += z[i] / 10;
        z[i] %= 10;
    }
    while (z[z[0] + 1] > 0) 
    {
        z[0]++;
        z[z[0] + 1] += z[z[0]] / 10;
        z[z[0]] %= 10;
    }
}
int main()
{
    long long t;
    cin >> t;
    while (t--)
    {
        i2BIG(1, mul);
        long long n, a, ans = 0;
        cin >> n >> a;
        for (int i = 1; i <= n; i++) mulBIG(mul,i,mul);
        for (int i = 1; i < mul[0]; i++) 
        {
            if (mul[i] == a) ans++;
        }
        cout << ans << "\n";
        memset(mul, 0, sizeof(mul));
    }
    return 0;
}

|