Skip to content

Instantly share code, notes, and snippets.

@jamiees2
Created May 6, 2013 15:36
Show Gist options
  • Save jamiees2/5525902 to your computer and use it in GitHub Desktop.
Save jamiees2/5525902 to your computer and use it in GitHub Desktop.
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