XOR POWER

All submissions for this problem are available.
A number is called a UNIQUE if that number when represented as powers of 3 then XOR ($\oplus$) of all the exponents should be zero. While representing a number in the powers of 3, priorities are given to the larger powers of 3 and take every exponent in the XOR sum. For example:  $20 = 3^2 + 3^2 + 3^0 + 3^0$ $(2\oplus2\oplus0\oplus0 = 0)$  $61 = 3^3 + 3^3 + 3^1 + 3^1 + 3^0$ $(3\oplus3\oplus1\oplus1\oplus0 = 0)$  $36 = 3^3 + 3^2$ $(3\oplus2 = 1)$  $81 = 3^4$ $(4 = 4)$ From the abovegiven numbers, $20$ and $61$ are UNIQUE numbers while $36$ and $81$ are not. You are given a positive number $N$ and you have to find the $smallest$ $UNIQUE$ $number$ $greater$ $than$ $or$ $equal$ $to$ $N$. ###Input:  First line will contain $T$, number of testcases. Then the testcases follow.  Each testcase contains of a single line of input, one integer $N$. ###Output: For each testcase, output in a single line answer which is the UNIQUE number just greater than or equal to $N$. ###Constraints  $1 \leq T \leq 10^{5}$  $1 \leq N \leq 10^{6}$ ###Sample Input: 2 2 3 ###Sample Output: 2 6 ###EXPLANATION: For the first case, $2 = 3^0 + 3^0$ $(0\oplus0 = 0)$, so 2 is the answer. For the second case, $3 = 3^1$ here XOR sum is not $0$ So the next number you can get is $6 = 3^1 + 3^1$ $(1\oplus1 = 0)$.Author:  yadvendra20 
Tags  yadvendra20 
Date Added:  22122019 
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, rust, SCALA, swift, 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, SQL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 