1 条题解

  • 0
    @ 2022-6-12 10:29:38
    #include<iostream>
    #include<cstring>
    #include<cmath>
    using namespace std;
    int p,base[1005],ans[1005],cache[1005],lena=1,lenb=1,lenc;
    void smartPlus(int u,int x){
    	int p=cache[u]+x;
    	if(p<10){
    		cache[u]=p;
    		return;
    	}
    	cache[u]=p%10;
    	smartPlus(u+1,p/10);
    }
    void plans(){
    	memset(cache,0,sizeof(cache));
    	for(int i=1;i<=500;i++){
    		for(int j=1;j<=500;j++){
    			//cout<<"1 "<<i+j-1<<' '<<ans[i]<<' '<<base[j]<<endl;
    			smartPlus(i+j-1,ans[i]*base[j]);
    		}
    	}
    	memcpy(ans,cache,sizeof(ans));
    }
    void plbase(){
    	memset(cache,0,sizeof(cache));
    	for(int i=1;i<=500;i++){
    		for(int j=1;j<=500;j++){
    			//cout<<"2 "<<i+j-1<<' '<<base[j]<<endl;
    			smartPlus(i+j-1,base[i]*base[j]);
    		}
    	}
    	memcpy(base,cache,sizeof(base));
    }
    int main(){
    	cin>>p;
    	ans[1]=1;
    	base[1]=2;
    	cout<<ceil(p*log10(2))<<endl;
    	while(p!=0){
    		if(p&1){
    			plans();
    		}
    		p>>=1;
    		plbase();
    	}
    	ans[1]-=1;
    	for(int i=500;i>=1;i--){
    		if(i!=500&&i%50==0)
    			cout<<endl;
    		cout<<ans[i];
    	} 
    	return 0;
    }
    
    • 1

    信息

    ID
    46
    时间
    1000ms
    内存
    125MiB
    难度
    3
    标签
    递交数
    26
    已通过
    12
    上传者