
The first line of input contains an integer 'T' representing the number of test cases.
The first line of each test case contains a single integer ‘N’.
For each test case, return 1 if the number 'N' can be represented as the distinct powers of 3 else return 0.
The output for each test case is printed 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 <= 5
1 <= N <= 10^9
Time limit: 1 second
This is just the recursive implementation of the previous approach. Instead of using an iterative approach, we can use a recursive function where the base case is ‘N’ == 1.
Algorithm:
The idea here is that if a number’s remainder with 3 is 2 then it is impossible to write that number as a distinct power of 3 because it is not possible to make 2 with any power of 3.
So we will keep on dividing ‘N’ till we either reach ‘N’ == 0 or ‘N’ % 3 == 2.
Algorithm:
Sorted Doubly Linked List to Balanced BST
Longest Substring with K-Repeating Characters
Expression Add Operators
Gray Code Transformation
Count of Subsequences with Given Sum