Skip to content

Instantly share code, notes, and snippets.

@Rishav159
Created May 28, 2017 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rishav159/6677e0eeeae12deb62acf743bc2e5de3 to your computer and use it in GitHub Desktop.
Save Rishav159/6677e0eeeae12deb62acf743bc2e5de3 to your computer and use it in GitHub Desktop.
Bond
t = int(input())
for test in range(t):
n = int(input())
i = 0
while(True):
if n < 2**i:
i = i-1
break
else:
i += 1
x = abs(2**i - n)
y = abs(2**(i+1) - n)
ans = min(x,y)
print(ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment