原文:
Palindromes are numbers that read the same forwards as backwards. The number 12321 is a typical palindrome.
Given a number base B (2 <= B <= 20 base 10), print all the integers N (1 <= N <= 300 base 10) such that the square of N is palindromic when expressed in base B; also print the value of that palindromic square. Use the letters ‘A’, ‘B’, and so on to represent the digits 10, 11, and so on.
Print both the number and its square in base B.
1 | PROGRAM NAME: palsquare |
翻译:平方回文
回文数字是指从后往前读以及从前往后读都一样的数字。 12321是一个典型的回文。
给出一个进制B(2<=B<=20),打印出所有的整数N(1<=N<=300 该进制下的,如B=10,那么就是10进制),他自己本身
是回文数,他的平方也是回文数字,使用”A”, “B” 等字母表示其他进制下的”10”, “11”..以此类推。
程序名称:palsquare 输入格式 B,进制 单行。 输入样例(文件palsquare.in) 10 输出格式 每行两个整数,第一个是回文数本身,第二个是他的平方。 输出样本(文件palsquare.out) 1 1 2 4 3 9 11 121 22 484 26 676 101 10201 111 12321 121 14641 202 40804 212 44944 264 69696
代码:
1 | /* |
结果:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40USER: 领 盛 [sunsetx1]
TASK: palsquare
LANG: C++
Compiling...
Compile: OK
Executing...
Test 1: TEST OK [0.000 secs, 3504 KB]
Test 2: TEST OK [0.000 secs, 3504 KB]
Test 3: TEST OK [0.000 secs, 3504 KB]
Test 4: TEST OK [0.011 secs, 3504 KB]
Test 5: TEST OK [0.000 secs, 3504 KB]
Test 6: TEST OK [0.000 secs, 3504 KB]
Test 7: TEST OK [0.000 secs, 3504 KB]
Test 8: TEST OK [0.000 secs, 3504 KB]
All tests OK.
Your program ('palsquare') produced all correct answers!
This is your submission #3 for this problem. Congratulations!
Here are the test data inputs:
------- test 1 ----
10
------- test 2 ----
2
------- test 3 ----
5
------- test 4 ----
11
------- test 5 ----
15
------- test 6 ----
18
------- test 7 ----
20
------- test 8 ----
3
Keep up the good work!
Thanks for your submission!
版权声明
本文标题:12_USACO_Section-1.2_Palindromic-Squares-平方回文数
文章作者:盛领
发布时间:2015年02月09日 - 17:55:25
原始链接:http://blog.xiaoyuyu.net/post/9ae1f180.html
许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。
如您有任何商业合作或者授权方面的协商,请给我留言:sunsetxiao@126.com