-
-
Save choro3/5381490 to your computer and use it in GitHub Desktop.
GCJ 2013 Qual C
http://oeis.org/A057135
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
import bisect | |
def palindromes(): | |
for d in xrange(7): | |
for i in xrange(10 ** d, 10 ** (d + 1)): | |
yield i * 10**d + long(str(i)[::-1]) % (10 ** d) | |
for i in xrange(10 ** d, 10 ** (d + 1)): | |
yield i * 10**(d + 1) + long(str(i)[::-1]) | |
def check(n): | |
return str(n) == str(n)[::-1] | |
def main(): | |
v = [i * i for i in palindromes() if check(i * i)] | |
N = int(raw_input()) | |
for tc in xrange(1, N + 1): | |
A, B = map(long, raw_input().split()) | |
print 'Case #%d: %d' % (tc, bisect.bisect_right(v, B) - bisect.bisect_left(v, A)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment