棋盘覆盖(大数处理)

f(x)=4*f(x-1)+1

1=<x<=100

十位数字后溢出  有效9.63位

 

19位数字后溢出  有效18  (9.63*2)

分析:得使用大数处理,与大整数乘法类似

//计算 N!  30
#include<iostream>
#include<cstring>
using namespace std;
const int maxn=20000;
int n,c,k,i,j;
int f[maxn+1];
int main() 
{
    while(cin>>n){
if(n==0){
    cout<<0<<endl;
    continue;
}
        memset(f,0,sizeof(f));
        f[0]=0;
        for(i=1;i<=n;i++){
            c=0;//表示进位
        for(j=0;j<=maxn;j++){
            f[j]=f[j]*4+c;
            c=f[j]/100000;
            f[j]=f[j]%100000;
        } 
        f[0]+=1;
        c=f[0]/100000;//表示进位
        f[0]%=100000;
        for(j=1;j<=maxn;j++){
            f[j]=f[j]+c;
            c=f[j]/100000;
            f[j]=f[j]%100000;
        }
        }

        for(k=maxn;k>=0;k--)
            if(f[k]!=0) break;
            cout<<f[k];
            for(j=k-1;j>=0;j--)
            printf("%05d",f[j]);//5位的数字不足前面添0 
            cout<<endl;
        }
}
View Code

 

posted @ 2019-03-19 15:32  Hello_World2020  阅读(220)  评论(0编辑  收藏  举报