0分求助!!!第一个回复有惊喜(私信)

P1591 阶乘数码

dongrq_cs @ 2023-04-01 20:13:28

#include <bits/stdc++.h>
using namespace std;
int n;
int a[1001],b[1001];
int f(int a){
    int sum = 1;
    for(int i = 1;i <= a;i++){
        sum *= i;
    }
    return sum;
}
int main(){
    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> a[i] >> b[i];
    }
    for(int i = 0;i < n;i++){
        int cnt = 0;
        int m = f(a[i]);
        while(m){
            if(m % 10 == b[i]){
                cnt++;
            }
            m /= 10;
        }
        cout << cnt << endl;
    }
    return 0;
}

by wangjiawen @ 2023-04-01 20:30:34

t是次数,t<=10。而n是阶乘,n<=1000。 1000!要高精了


by hank0402 @ 2023-04-01 20:31:00

你可以把你的代码改成py,或者随手撒一个高精乘低精(很好写吧)


by dongrq_cs @ 2023-04-01 20:32:14

好的


by ShenEric @ 2023-04-02 20:23:59

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<iostream>
using namespace std;

int main()
{
    int a[5000];
    int t;
    cin>>t;
    while (t--)
    {
        int n,i,j,k,m;
        long long sum=0;
        int p=1,jw=0;
        for (int i=1;i<=1001;i++)
        {
            a[i]=0;
        }
        a[1]=1;
        scanf("%d%d",&n,&m);
        for(i=2;i<=n;i++)
        {
            jw=0;
            for(j=1;j<=p;j++)
            {
                a[j]=a[j]*i+jw;
                jw=a[j]/10;
                a[j]=a[j]%10;
            }
            while(jw>0)
            {
                a[j]=jw%10;
                jw/=10;
                j++;
            }
            p=j-1;
        }
        for (i=p;i>=1;i--)
        {
            if (a[i]==m)
            {
                sum++;
            }
        }
        cout<<sum<<endl;
    }
    return 0;
}

老久以前做的了,思路忘记了,就将就着看吧


by zhanghy123 @ 2023-04-03 20:46:56

@dongrq_cs 直接告诉你吧,根本不够

4.02387260077093773543702433923e+2567

大约相当于10的两千多次方,long long 最多10^18左右


by aidsao @ 2023-04-05 13:17:55

@dongrq_cs 你这不废话吗,不开long long见祖宗


by dongrq_cs @ 2023-04-05 20:41:33

@aiwdsao

谢!!

抱歉,才看到。。。


by aidsao @ 2023-04-05 21:14:24

@dongrq_cs 没关系,我也是蒻


by estar_17k @ 2023-04-15 16:59:00

用long long 啊!


by Bauman @ 2023-04-17 15:38:33

long long 也存不了啊!拜托!!!


上一页 | 下一页