Posted on 2009-03-16 19:33
superman 阅读(49)
评论(0) 编辑 收藏 引用 所属分类:
USACO
1 #include <iostream>
2
3 using namespace std;
4
5 string num2string(int n, int b)
6 {
7 string s;
8 while (n)
9 {
10 s += "0123456789"[n % b];
11 n /= b;
12 }
13 for (unsigned i = 0; i < s.size() / 2; i++)
14 swap(s[i], s[s.size() - i - 1]);
15 return s;
16 }
17
18 bool isPalindrome(const string & s)
19 {
20 for (unsigned i = 0; i < s.size() / 2; i++)
21 if (s[i] != s[s.size() - i - 1])
22 return false;
23 return true;
24 }
25
26 int main()
27 {
28 freopen("dualpal.in", "r", stdin);
29 freopen("dualpal.out", "w", stdout);
30
31 int n, s;
32
33 cin >> n >> s;
34 for (int i = 0, j = s + 1; i < n; j++)
35 {
36 int cnt = 0;
37 for (int b = 2; b <= 10; b++)
38 cnt += isPalindrome(num2string(j, b));
39 if (cnt >= 2)
40 {
41 cout << j << endl;
42 i += 1;
43 }
44 }
45
46 return 0;
47 }
48