1 /* 2 POJ2116 Death to Binary? 3 http://poj.org/problem?id=2116 4 齐肯多夫定理 5 6 */ 7 #include <cstdio> 8 #include <algorithm> 9 #include <cstring> 10 #include <cmath> 11 #include <vector> 12 #include <queue> 13 #include <iostream> 14 #include <map> 15 #include <set> 16 //#define test 17 using namespace std; 18 const int Nmax=1e6+7; 19 char s[50],a[50],b[50],c[50],tmp[50],t[50]; 20 long long f[50]; 21 vector<long long> v; 22 vector<long long>::iterator it; 23 long long scan() 24 { 25 char c=getchar(); 26 while(c==' '||c==' ') 27 c=getchar(); 28 if(c==-1) 29 return -1; 30 int sz=0; 31 while(c>='0' && c<='1') 32 { 33 s[++sz]=c; 34 c=getchar(); 35 } 36 long long x=0LL; 37 for(int i=1;i<=sz;i++) 38 { 39 x+=1LL*(s[i]-'0')*f[sz-i]; 40 } 41 return x; 42 } 43 int id(long long x) 44 { 45 int now=upper_bound(v.begin(),v.end(),x)-v.begin(); 46 if(now!=0) 47 now--; 48 return now; 49 } 50 char* get(long long x) 51 { 52 int sz=0; 53 for(int i=0;i<=40;i++) 54 tmp[i]='0'; 55 //printf(" "); 56 while(x>0) 57 { 58 //printf("x:%lld ",x); 59 tmp[id(x)]='1'; 60 sz=max(sz,id(x)); 61 //printf("%d ",id(x)); 62 //printf("%lld",f[id(x)]); 63 x-=f[id(x)]; 64 } 65 //printf(" "); 66 //for(int i=0;i<=40;i++) 67 //printf("%c",tmp[i]); 68 //printf(" "); 69 70 //printf("%s ",tmp); 71 72 for(int i=sz;i>=0;i--) 73 t[sz-i]=tmp[i]; 74 t[sz+1]='