Advertisement
AncientPC

Untitled

Apr 17th, 2012
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  1. #!/usr/bin/env python2
  2.  
  3. def permutations(a,b,x):
  4.  
  5.     y = str(x)
  6.     cnt = 0
  7.     for i in range(1,len(y)):
  8.         j = int(y[i:]+y[:i])
  9.         if j == x:
  10.             break
  11.         elif j > x and j >= a and j <= b:
  12.             cnt += 1
  13.  
  14.     return cnt
  15.  
  16. nc = int(raw_input())
  17. for c in xrange(nc):
  18.     a, b = map(int,raw_input().split())
  19.  
  20.     cnt = 0
  21.     for i in range(a,b+1):
  22.         cnt += permutations(a,b,i)
  23.  
  24.     print "Case #%i: %i" % (c+1, cnt)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement