Skip to content

Instantly share code, notes, and snippets.

@jtwaleson
Created April 15, 2012 14:12
Show Gist options
  • Save jtwaleson/2393063 to your computer and use it in GitHub Desktop.
Save jtwaleson/2393063 to your computer and use it in GitHub Desktop.
C - Recycled Numbers
from sys import stdin
def rline():
return stdin.readline().rstrip()
for l in range(int(rline())):
(n,m) = map(int, rline().split())
total = 0
length = len(str(n))
for k in range(n, m+1):
s1 = str(k)
total += len([x for x in set([int(s1[n:]+s1[:n]) for n in range(length)]) if x > k and x <= m])
print "Case #%s: %s" % (l+1, total)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment