The first line of input contains an integer ‘T’ representing the number of test cases.
The first and the only line of each test case contains the integer ‘N’ denoting the number.
For each test case, on a separate line, output one integer 0 or 1. Print 1, if N is a power of 3, or 0 otherwise.
Print the output of each test case in a separate line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 10^9
Time limit: 1 sec
Approach: The idea here is to keep dividing ‘N’ by 3 every time till ‘N’ is divisible by 3. If at the end N is greater than 1 then the number will not be divisible by 3.
The algorithm is as follows :
Merge Two Sorted Arrays Without Extra Space
Ninja And The Strictly Increasing Array
Maximum GCD
Prime?
Co-Prime