https://www.luogu.org/problemnew/show/P1045
高精度板子:
快速幂:
ll quickPower(ll a,ll b){
ll ans=1,base=a;
while(b>0){
if(b&1)
ans*=base;
base*=base;
b>>=1;
}
return ans;
}
还涉及到取对数的问题
#include <bits/stdc++.h>
#define FF(a,b) for(int a=0;a<b;a++)
#define F(a,b) for(int a=1;a<=b;a++)
#define LEN 510000
#define INF 1000000
#define bug(x) cout<<#x<<"="<<x<<endl;
using namespace std;
int P;
int L=500;
struct hp{
int len;
int *s;
hp(){
s=new int [LEN];
memset(s,0,4*LEN);
len=1;
}
hp(char* ch){
len=strlen(ch);
s=new int [LEN];
memset(s,0,4*LEN);
for(int i=1;i<=len;i++)
s[i]=ch[len-i]-48;
}
void print(){
int i;
for(i=500;i>=1;i--){
if(i%50==0) puts("");
printf("%d",s[i]);
}
}
};
hp multiplyh(const hp& a,const hp& b){
int i,j,len;
hp c;
for(i=1;i<=a.len;i++){
for(j=1;j<=b.len;j++){
c.s[i+j-1]+=a.s[i]*b.s[j];
c.s[i+j]+=c.s[i+j-1]/10;
c.s[i+j-1]%=10;
}
}
len=a.len+b.len+1;
while(len>1 && c.s[len]==0)len--;
c.len=len;
if(c.len>=L){//截取最后500项
c.len=500;
}
return c;
}
int main()
{
freopen("./in","r",stdin);
scanf("%d",&P);
printf("%d",int( log10(2)*P + 1) );
hp ans("1");
hp base("2");
while(P>0){
if(P&1)
ans=multiplyh(ans,base);
base= multiplyh(base,base);
P>>=1;
}
ans.s[1]-=1;
ans.print();
return 0;
}