Created
May 6, 2013 15:36
-
-
Save jamiees2/5525902 to your computer and use it in GitHub Desktop.
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
complement_memo = {} | |
def complement(ar): | |
a, b = ar | |
total = 0 | |
for i in xrange(a,b+1): | |
if not i in complement_memo: | |
complement_memo[i] = count(i) | |
total += complement_memo[i] | |
print total | |
def count(u): | |
uCount = u - ((u >> 1) & 033333333333) - ((u >> 2) & 011111111111); | |
return ((uCount + (uCount >> 3)) & 030707070707) % 63; | |
if __name__ == "__main__": | |
m = input() | |
for i in xrange(m): | |
complement([int(i) for i in raw_input().strip().split()]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment