标签:
1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 using namespace std; 5 const int maxn=110; 6 struct ExtInt{ 7 int a[maxn],len; 8 ExtInt(){ 9 memset(a,0,sizeof(a)); 10 len=1; 11 } 12 void clear(){ 13 memset(a,0,sizeof(a)); 14 len=1; 15 } 16 int operator [](int x){ 17 return a[x]; 18 } 19 void Print(){ 20 for(int i=len;i>=1;i--) 21 printf("%d",a[i]); 22 printf("\n"); 23 } 24 }ans,F; 25 26 27 28 ExtInt operator /(ExtInt a,int x){ 29 ExtInt ret; 30 for(int i=a.len,tot=0;i>=1;i--){ 31 tot=tot*10+a[i]; 32 ret.a[i]=tot/x; 33 tot%=x; 34 } 35 ret.len=a.len; 36 while(!ret[ret.len]&&ret.len>1)ret.len-=1; 37 return ret; 38 } 39 40 ExtInt operator +(ExtInt a,int x){ 41 ExtInt ret; 42 for(int i=1,in=0;i<=a.len||in;i++){ 43 ret.a[i]=a[i]+in+x%10;x/=10; 44 in=ret.a[i]/10;ret.a[i]%=10; 45 } 46 ret.len=a.len+1; 47 while(!ret[ret.len]&&ret.len>1)ret.len-=1; 48 return ret; 49 } 50 ExtInt operator +(ExtInt a,ExtInt x){ 51 ExtInt ret; 52 for(int i=1,in=0;i<=max(a.len,x.len)||in;i++){ 53 ret.a[i]=in+a[i]+x.a[i]; 54 in=ret.a[i]/10;ret.a[i]%=10; 55 } 56 ret.len=max(a.len,x.len)+1; 57 while(!ret[ret.len]&&ret.len>1)ret.len-=1; 58 return ret; 59 } 60 61 ExtInt p,q; 62 void Solve(ExtInt x){ 63 if(x[1]==1&&x.len==1){ 64 p=x;q.clear(); 65 return; 66 } 67 Solve((x+1)/2); 68 if(x[1]&1)p=p+q; 69 else q=p+q; 70 } 71 72 char s[maxn]; 73 int main(){ 74 freopen("sequencezj.in","r",stdin); 75 freopen("sequencezj.out","w",stdout); 76 int T; 77 scanf("%d",&T); 78 while(T--){ 79 scanf("%s",s+1); 80 int len=strlen(s+1); 81 for(int i=1;i<=len;i++) 82 F.a[len-i+1]=s[i]-‘0‘; 83 F.len=len; 84 Solve(F); 85 p.Print(); 86 } 87 return 0; 88 }
标签:
原文地址:http://www.cnblogs.com/TenderRun/p/5592316.html