WA声一片啊!求助0.0

P1591 阶乘数码

FLoveQ @ 2023-08-30 18:07:47


#include<iostream>
#include<cstring>
using namespace std;
int num[3005];
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        memset(num, sizeof(num), 0);
        int a,n,x,up = 0,total = 0;
        cin >> n >> x;
        num[1] = 1;
        for( a = 2;a<=n;a++)
        for (int i = 1; i <= 3000; i++)
        {
            num[i] = num[i] * a + up;
            up = 0;
            if (num[i] > 10)
            {
                up = num[i] / 10;
                num[i] = num[i] % 10;
            }
        }
        int w = 0;
        for (int i = 3000;i>=1; i--)
        {
            if (num[i] != 0)
            {
                w = i; break;
           }
        }
        for (int i = 1; i <= w; i++)
        {
            if (num[i] == x) total++;
        }
        cout << total << endl;
    }
    return 0;
}
``

by FLoveQ @ 2023-08-30 18:41:52

@sunningyi 好的,谢谢大佬


by hm2ns @ 2023-08-30 18:50:56

@FLoveQ 你使用数组模拟也是可以的,因为这个题只是高精度乘单精度。但你要注意进位那个地方的判断和你循环的次数是不是有问题。


by FLoveQ @ 2023-08-30 18:55:42

@sunningyi 进位的次数确实出问题了


|