麦森数

P1045 [NOIP2003 普及组] 麦森数

chenkuo @ 2023-06-30 19:06:04

求助,样例也过不了。

┭┮﹏┭┮

#include<bits/stdc++.h>
#define longint long long
using namespace std;
int n;
longint a[1000],b[1000],s;
void change(longint a[],longint b[]){for(int i=0;i<=b[0];i++) a[i]=b[i];return;}
void multiplication(longint a[],longint b[]){
    longint c[502]={0},d[502]={0};
    for(int i=1;i<=b[0];i++){
        for(int j=1;j<=a[0];j++) c[j]=b[i]*a[j];
        for(int j=1;j<=a[0];j++) d[j+i-1]+=c[j];
    }
    int l=1;
    while(l<=500&&(l<=a[0]+b[0]+1||d[l]!=0)){
        d[l+1]+=d[l]/10;
        d[l]%=10;
        l++;
    }
    d[0]=l-3;
    change(a,d);
    return;
}
int main(){
    int u;
    scanf("%d",&n);
    printf("%d",(int)(log10(2)*n+1));
    a[0]=a[1]=1;
    b[0]=1;b[1]=2;
    while(n>0){
        if(n&1) multiplication(a,b);
        multiplication(b,b);
        n/=2;
    }
    for(int i=500;i>1;i--){
        if(i%50==0){
            cout<<endl;
        }
        printf("%lld",a[i]);
    }
    printf("%lld",a[1]-1);
}

by Poombom @ 2023-07-01 19:39:20

@chenkuo 这题要用高精……


by hjbaoyx @ 2023-07-25 09:53:10

@Poombom 纯高精只得50分


by hjbaoyx @ 2023-07-25 09:54:23

我就只有50分┭┮﹏┭┮


by exenthcig_a @ 2023-08-07 13:08:31

@baoyexuan (我纯高精60)


|