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:||ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 6.3, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYPY, PYTH, PYTH 3.5, RUBY, SCALA, SCM chicken, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC|
Fetching successful submissions
If you are still having problems, see a sample solution here.