问题:
如果一个整数n至少在两个不同进位制b1,b2下都是回文数(2≤b1,b2≤10)则n是双基回文数,注意回文数中不能包含前导0。输入n,n<1000000,输出比n大的最小双基回文数。
样例输入:
1600000
样例输出:
1632995
1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5 int i,j,k,flag,count = 0; 6 int a[50]; 7 long s,t; 8 cin>>s; 9 //s = 1600000; 10 while(1) 11 { 12 s++; 13 count = 0; 14 for(i = 2;i <= 10;i++) 15 { 16 flag = 1; 17 t = s; 18 k = 0; 19 do 20 { 21 a[k++] = t%i; 22 t = t/i; 23 }while(t); 24 25 if(k%2 == 0) 26 { 27 for(j = 0;j < k/2;j++) 28 { 29 if(a[j] != a[k-j-1]) 30 { 31 flag = 0; 32 break; 33 } 34 } 35 } 36 else 37 { 38 for(j = 0;j <= k/2;j++) 39 { 40 if(a[j] != a[k-j-1]) 41 { 42 flag = 0; 43 break; 44 } 45 } 46 } 47 if(flag == 1) 48 count++; 49 if(count == 2) 50 { 51 break; 52 } 53 } 54 if(count == 2) 55 break; 56 } 57 cout<<s<<endl; 58 /*for(i = 2;i <= 10;i++) 59 { 60 t = s; 61 k = 0; 62 do 63 { 64 a[k++] = t%i; 65 t = t/i; 66 }while(t); 67 68 for(j = 0;j < k;j++) 69 cout<<a[j]; 70 cout<<endl; 71 }*/ 72 return 0; 73 }