Chef and the XORed Number
All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Russian as well.
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1.
The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case.
For each test case, output a single line containing the number M or -1 as described above.
- 1 ≤ T ≤ 5000
- 1 ≤ N ≤ 230
Input: 1 3 Output: 1
First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
|Tags||basic-maths, bitwise-operatn, cook61, rustinpiece, simple|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions