自己测试数据都是对的但全wa

P1591 阶乘数码

JustBecause @ 2022-09-17 18:00:00

#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<iomanip>
#include<algorithm>
#pragma warning(disable:4996)
using namespace std;

int a[10000005], b[10000005], t[10000005];

int mult(int* a, int* b, int lena, int lenb)
{
    int jinwei = 0;
    int c[10000];
    for (int i = 0; i < 10000; i++)
    {
        c[i] = 0;
    }
    for (int i = 0; i < lenb; i++)//b[i]
    {
        jinwei = 0;
        for (int j = 0; j < lena; j++)
        {
            c[j + i] = c[j + i] + a[j] * b[i] + jinwei;
            jinwei = c[j + i] / 10;
            c[j + i] = c[j + i] % 10;
            if (j == lena - 1)
            {
                c[j + i + 1] = jinwei;
            }
        }
    }
    int index = lena + lenb;
    while (c[index] == 0 && index > 0)
    {
        index--;
    }
    for (int i = 0; i <= index; i++)
    {
        a[i] = c[i];
    }
    return index + 1;
}

int main()
{
    int m;
    cin >> m;
    int n;
    int x;
    for (int k= 1; k <= m; k++)
    {
        for (int i = 0; i <= 1000005; i++)
        {
            a[i] = 0;
            b[i] = 0;
        }
        cin >> n>>x;
        a[0] = 1;
        int lena = 1;
        int lenb;
        for (int i = 1; i <= n; i++)
        {
            if (i <= 9)
            {
                b[0] = i;
                lenb = 1;
            }
            else
            {
                b[1] = i / 10;
                b[0] = i % 10;
                lenb = 2;
            }
            lena = mult(a, b, lena, lenb);
        }
        int ans = 0;
        for (int i = lena - 1; i >= 0; i--)
        {
            if (a[i] == x)
            {
                ans++;
            }
        }
        cout <<ans<< endl;
    }
    return 0;
}

|