50px,5TLE

P1045 [NOIP2003 普及组] 麦森数

laozhang_123 @ 2023-12-15 19:37:13

#include<bits/stdc++.h>
#define maxn 1000000
using namespace std;
struct Bigint{
    int len,a[maxn];
    Bigint(int x=0){
        memset(a,0,sizeof(a));
        for(len=1;x;len++)
            a[len]=x%10,x/=10;
        len--;
    }
    int &operator[](int i){
        return a[i];
    }
    void flatten(int L){
        len=L;
        for(int i=1;i<=len;i++)
            a[i+1]+=a[i]/10,a[i]%=10;
        for(;!a[len];) len--;
    }
    void print(){
        if(len<500){
            int i=1;
            for(i=499;i>len;i--){
                printf("0");
                if(i%50==0) printf("\n");}
            i++;
            for(;i>=1;i--){
                printf("%d",a[i]);
                if(i%50==1) printf("\n");}}
        if(len>=500){
            Bigint ans;
            for(int i=1;i<=500;i++) ans[i]=a[i];
            for(int i=500;i>=1;i--){
                printf("%d",ans[i]);
                if(i%50==1) printf("\n");}}
    }
}; 
Bigint operator*(Bigint a,Bigint b){
    Bigint c;
    int lena=a.len,lenb=b.len;
    for(int i=1;i<=lena;i++){
        for(int j=1;j<=lenb;j++)c[i+j-1]+=a[i]*b[j];}
    int len=lena+lenb;
    c.flatten(len+110);
    return c;
}
int main(){
    int a;
    cin>>a;
    Bigint mid(1),ans(1);
    for(int i=1;i<=30;i++) mid=mid*Bigint(2);
    for(int i=1;i<=a/30;i++) ans=ans*mid;
    for(int i=1;i<=a%30;i++) ans=ans*Bigint(2);
    ans.a[1]-=1;
    cout<<ans.len<<endl;
    ans.print();
    return 0;
}

by jinglinbankemeng @ 2023-12-15 21:02:37

改了之后,发现不行!


by jinglinbankemeng @ 2023-12-15 23:03:50

https://www.luogu.com.cn/record/139738566


|