样例过了0分wa求调

P1591 阶乘数码

Meguru_Bachira @ 2024-10-11 19:34:29

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll t,n,a,ans[1000005],now;
void f(){
    for (int i=1;i<=ans[0];i++){
        if (ans[i]>=10){
            if (!ans[i+1]){
                ans[0]++;
            }
            ans[i+1]+=ans[i]/10;
            ans[i]%=10;
        }
    }
}
int main(){
    cin >> t;
    while(t--){
        cin >> n >> a;
        now=0;
        memset(ans,0,sizeof(ans));
        ans[0]=1;
        ans[1]=1;
        for (int i=2;i<=n;i++){
            for (int j=1;j<=ans[0];j++){
                ans[j]*=i;
            }
        }
        f();
        for (int k=1;k<=ans[0];k++){
            if (ans[k]==a){
                now++;
            }
        }
        cout << now << endl;
    }
}

|