c
Python
code posted
created at 14 Apr 03:55
Edit
|
Back
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
T = int(raw_input()) it = 400401 palindromes = [1, 4, 9, 121, 484, 10201, 12321, 14641, 40804, 44944, 1002001, 1234321, 4008004, 100020001, 102030201, 104060401, 121242121, 123454321, 125686521, 400080004, 404090404, 10000200001, 10221412201, 12102420121, 12345654321, 40000800004, 1000002000001, 1002003002001, 1004006004001, 1020304030201, 1022325232201, 1024348434201, 1210024200121, 1212225222121, 1214428244121, 1232346432321, 1234567654321, 4000008000004, 4004009004004] while it < 1000001: str_it = str(it) for i in ["", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]: pit = int(str_it + i + str_it[::-1]) palindromes.append(pit * pit) it += 1 def calc(A,B): count = 0 for i in palindromes: if i >= A and i <= B: count += 1 if i > B: break return count for test in range(1, T + 1): A, B = [int(i) for i in raw_input().split()] print "Case #%d: %d" % (test, calc(A, B)) |
993 Bytes in 4 ms with coderay