Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import sys
- def lb(x):
- r = 1
- while x&r == 0:
- r = r*2
- return r
- def pos(l, v):
- f = lambda x : lb(x-v) if x != v else 2**420
- k = sorted(l, key=f)
- for i in xrange(len(k)-1):
- r, s, t = abs(k[i+1]-k[i]), f(k[i]), f(k[i+1])
- if r % (2*s) != s or r > 2*t-s:
- return False
- return True
- l = map(int,raw_input())
- l.sort()
- for i in xrange(1,len(l)):
- if l[i] == l[i-1]:
- print 'Invalid'
- sys.exit(0)
- if pos(l,l[0]) or pos(l,l[-1]):
- print 'Valid'
- else:
- print 'Invalid'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement