陈yu200010 @ 2017-05-10 19:45:26
#include<stdio.h>
#include<cstdlib>
#include<string.h>
#include<math.h>
#define maxn 570
typedef struct
{
long a[maxn];
}bign;
void mul(bign &c,bign &a,bign &b)
{
memset(c.a,0,sizeof(c.a));
for(long i=0;i<=499;i++)
for(long j=0;j<=499-i;j++)
c.a[i+j]+=a.a[i]*b.a[j];
for(long i=0;i<=499;i++)
if(c.a[i]>=10)
{
c.a[i+1]+=c.a[i]/10;
c.a[i]%=10;
}
c.a[500]=0;
}
int main()
{
long n,m,count;
bign _2[maxn]={{1},{2}},ans={{1}},t;
scanf("%ld",&n);
// Input
printf("%ld\n",(long)(n*log10(2))+1);
m=(long)(log(n)/log(2))+3;
for(long i=2;i<=m;i++)
mul(_2[i],_2[i-1],_2[i-1]);
count=0;
while(n>0)
{
if(n%2==1)
{
t=ans;
mul(ans,t,_2[count+1]);
}
count++;n/=2;
}
ans.a[0]--;
for(long i=499;i>=0;i--)
printf("%ld",ans.a[i]);
putchar('\n');
system("pause");
}
by 陈yu200010 @ 2017-05-10 19:52:30
额,好吧,超时了