[help] 25sc, dk why

P1009 [NOIP1998 普及组] 阶乘之和

ms_xg_mx @ 2024-06-29 14:01:49

#include<bits/stdc++.h>
using namespace std;
short sum[100];
short num[70];
void reset(){
    for(int i=0;i<70;i++){
        num[i]=0;
    }
}
void multiply(int x){
    for(int i=0;i<70;i++){
        num[i]*=x;
    }
    for(int i=0;i<70;i++){
        if(num[i]>10){
            num[i+1]+=num[i]/10;
            num[i]%=10;
        }
    }
}
void add(){
    for(int i=0;i<70;i++){
        sum[i]+=num[i];
    }
    for(int i=0;i<100;i++){
        if(sum[i]>10){
            sum[i+1]+=sum[i]/10;
            sum[i]%=10;
        }
    }
}
void input(int x){
    int i=0;
    while(x>0){
        num[i]=x%10;
        x/=10;
        i++;
    }
}
void print(){
    bool f=0;
    for(int i=99;i>=0;i--){
        if(sum[i]!=0) f=1;
        if(f) cout<<sum[i];
    }
}
void testprint(){
    bool f=0;
    for(int i=69;i>=0;i--){
        if(num[i]!=0) f=1;
        if(f) cout<<num[i];
    }
    cout<<endl;
}

int main(){
    int n;
    n=10;
    for(int i=1;i<=n;i++){
        reset();
        input(i);
        for(int j=i-1;j>0;j--){
            multiply(j);
        }
        //testprint();
        add();
    }
    print();
    return 0;
}

想法:

^&没$#有%`想@-法*!

不知道为什么过不了

record:

大佬救我!!!我怎么高精度都不会了!!!


by afkesibu @ 2024-06-29 14:39:41

答案仅供参考


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a[]={"1","3","9","33","153","873","5913","46233","409113","4037913","43954713","522956313","6749977113","93928268313","1401602636313","22324392524313","378011820620313","6780385526348313","128425485935180313","2561327494111820313","53652269665821260313","1177652997443428940313","27029669736328405580313","647478071469567844940313","16158688114800553828940313","419450149241406189412940313","11308319599659758350180940313","316196664211373618851684940313","9157958657951075573395300940313","274410818470142134209703780940313","8497249472648064951935266660940313","271628086406341595119153278820940313","8954945705218228090637347680100940313","304187744744822368938255957323620940313","10637335711130967298604907294846820940313","382630662501032184766604355445682020940313","14146383753727377231082583937026584420940313","537169001220328488991089808037100875620940313","20935051082417771847631371547939998232420940313","836850334330315506193242641144055892504420940313","34289376947494122614363304694584807557656420940313","1439295494700374021157505910939096377494040420940313","61854558558074209658512637979453093884758552420940313","2720126133346522977702138448994068984204397080420940313","122342346998826717539665299944651784048588130840420940313","5624964506810915667389970728744906677010239883800420940313","264248206017979096310354325882356886646207872272920420940313","12678163798554051767172643373255731925167694226950680420940313","620960027832821612639424806694551108812720525606160920420940313","31035053229546199656252032972759319953190362094566672920420940313"};
    int b;
    cin>>b;
    cout<<a[b-1]<<endl;
    return 0;
}

by tribool4_in @ 2024-06-29 15:03:57

@ms_xg_mx 你第 15 行和第 26 行两处判断进位写成了 >10 而非 >=10


by ms_xg_mx @ 2024-06-29 21:22:03

@afkesibu 我。。。好吧。。。这,,,


by ms_xg_mx @ 2024-06-29 21:35:11

@tribool4_in record

ac了,谢谢


|