//这道题难度不大,用最简单的枚举就可以了。
//题目: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=78
#include<iostream> #include<string> using namespace std; bool judge(int); int m; int b[1000000]; int a[15]; int main() { int i, j, k, n,flag; while (cin >> m&&m!=0) { flag = 0; j = 0; for (i = 2; i <= 16; i++) { n = m; int x = 0; while (n != 0) { k = n%i; n = n / i; b[x] = k; x++; } if (judge(x)) { flag = 1; a[j] = i; j++; } } if (flag == 1) { cout << "Number " << m << " is palindrom in basis"; for (i = 0; i < j; i++) { cout << " " << a[i]; } cout << endl; } else cout << "Number " << m << " is not a palindrom" << endl; } return 0; } bool judge(int x) { for (int i = 0; i < x; i++) { if (b[i] != b[x - 1 - i])return 0; } return 1; }