P1045 麦森数(高精)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=1010;
int p;
int f[N],res[N],sav[N];
void mul(int a[],int b[],int c[]){
memset(sav,0,sizeof sav);
for(int i=1;i<=500;i++)
for(int j=1;j<=500;j++)
sav[i+j-1]+=a[i]*b[j];
for(int i=1;i<=500;i++){
sav[i+1]+=sav[i]/10;
sav[i]%=10;
}
memcpy(c,sav,sizeof sav);
}
int main()
{
cin>>p;
cout<<(int)(log10(2)*p+1)<<endl;
f[1]=2;
res[1]=1;
while(p){
if(p&1) mul(res,f,res);
p>>=1;
mul(f,f,f);
}
res[1]-=1;
for(int i=500;i>=1;i--){
if(i!=500&&i%50==0) puts("");
cout<<res[i];
}
return 0;
}