Rachel·Gardner @ 2018-07-03 00:25:56
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=510;
int p;
int ans[N];
int a[N],b[N];
void mult(int *a,int *b) {
int c[N];
memset(c,0,sizeof(c));
for(int i=0; i<500; i++)
for(int j=0; j<500; j++) {
if(i+j<500) {
c[i+j]+=a[i]*b[j];
c[i+j+1]+=c[i+j]/10;
c[i+j]%=10;
}
}
memcpy(a,c,500*sizeof(int));
}
void dfs(int m) {
while(m) {
if(m%2==1)
mult(ans,a);
m/=2;
mult(a,a);
}
}
int main () {
scanf("%d",&p);
int m=p;
memset(a,0,sizeof(a));
memset(ans,0,sizeof(ans));
a[0]=2;
ans[0]=1;
dfs(m);
ans[0]--;
printf("%d\n",(int)(p*log10(2.0)+1));
for(int i=499; i>=0; i--)
printf("%d",ans[i]);
return 0;
}
by 星小雨 @ 2018-07-03 08:12:19
题目说每行输出50位。。。
by Rachel·Gardner @ 2018-07-03 22:12:14
@十字军 Thanks♪(・ω・)ノ