Max6700 @ 2024-07-25 17:51:38
蹲如何快速幂优化
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n;
int m[5100]={1,1};
void mBIG(int a[],int b,int c[])
{
int u=0;
int t=0;
for(int i=1;i<=a[0];i++)
{
t=a[i]*b+u;
c[i]=t%10;
u=t/10;
}
int len=c[0];
while(u>0)
{
len++;
c[len]=u%10;
u/=10;
}
// c[0]=min(500,c[0]);
c[0]=500;
}
ll cnt;
int main(){
cin>>n;
for(int i=1;i<=n;i++)
mBIG(m,2,m);
cout<<int(log10(2)*n+1)<<"\n";
m[1]--;
for(int i=500;i>=1;i--)
{
cnt++;
cout<<m[i];
if(cnt%50==0)cout<<"\n";
}
return 0;
}
by YuhongZhou @ 2024-07-26 22:09:52
幂优化还过不去,需要再加上数学方法加上保留后500位