2的幂次大数运算

#include<bits/stdc++.h>
using namespace std;
const int maxsize=1e5+10;
int a[maxsize];
int main(){
    int n;
    while(~scanf("%d",&n)){
        memset(a,0,sizeof(a));
        a[0]=2;
        int cursize=0;
        for(int i=1;i<n;i++){
            int jinwei=0;
            for(int j=0;j<=cursize;j++){
                int tem=2*a[j];
                if(jinwei==1) tem+=1;
                if(tem>=10) jinwei=1;
                else jinwei=0;
                a[j]=tem%10;
            }
            if(jinwei==1){
                cursize++;
                a[cursize]=1;//因为某个数乘以2的进位绝对是1 
            }
        }
        for(int i=cursize;i>=0;i--)
        printf("%d",a[i]);
        printf("\n");
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/mch5201314/p/10287402.html
今日推荐