Help me!!!

P1591 阶乘数码

梦理乾坤 @ 2020-04-23 16:10:39

#include <iostream>
#include <cstring>

using namespace std;

int f[100010];

int main()
{
    int t;
    cin >> t;

    while (t -- )
    {
        int n, a;
        cin >> n >> a;

        memset(f, 0, sizeof f);
        f[1] = 1;
        int l = 1;
        for (int i = 2; i <= n; i ++ )
        {
            int w = 0;
            for (int j = 1; j <= l; j ++ )
            {
                f[j] = f[j] * i + w;
                w = f[j] / 10;
                f[j] %= 10;
            }
            l ++ ;
            while (w)
            {
                f[l] = w % 10;
                l ++ ;
                w /= 10;
            }
        }

        int sum = 0;

        for (int i = 1; i <= l; i ++ )
            if (f[i] == a)  sum ++ ;

        cout << sum << endl;
    }

    return 0;
}

by 老子是北瓜 @ 2020-04-23 16:11:30

How can I help you?


by 梦理乾坤 @ 2020-04-23 16:12:51

告诉一下我那错了


by 老子是北瓜 @ 2020-04-23 16:18:37

TLE or WA?


by 吴勉之 @ 2020-04-23 16:19:48

@•╬• 不是乘啥都l++的

int w = 0;
            for (int j = 1; j <= l; j ++ )
            {
                f[j] = f[j] * i + w;
                w = f[j] / 10;
                f[j] %= 10;
            }
            l ++ ;//就是这
            while (w)
            {
                f[l] = w % 10;
                l ++ ;
                w /= 10;
            }

by 梦理乾坤 @ 2020-04-23 16:22:33

谢谢


by 修罗海神王 @ 2020-04-23 17:03:23

@老子是白菜 这个尴尬了……


by 梦理乾坤 @ 2020-05-09 22:36:44

@Minecraft万岁


by Minecraft万岁 @ 2020-05-10 00:21:53

Who are you?


|