Given an integer n, return true if n can be written as the sum of distinct powers of three, and false otherwise. A power of three is any number of the form 3^x for an integer x >= 0.
Given an integer n, return true if n can be written as the sum of distinct powers of three, and false otherwise. A power of three is any number of the form 3^x for an integer x >= 0.
Example 1:
Input: {"n":12}
Output: true
Constraints:
1≤n≤107
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"n":12}
Write 12 in base 3. Each power of three may be used at most once, so every base-3 digit must be 0 or 1.