An experimental capacitor called the Triplicator begins holding exactly 1 unit of charge. Every time it is activated, its stored charge is instantly multiplied by exactly 3. Given a target integer n, determine whether there exists some number of activations, zero or more, after which the Triplicator's stored charge equals exactly n.
A single line containing the integer n.
Print true if some non-negative number of activations produces a stored charge exactly equal to n, otherwise print false.
Example 1
Input
27
Expected
true
Explanation
27 = 3 * 3 * 3 = 3^3, reached after 3 activations starting from charge 1, so the answer is true.
Example 2
Input
45
Expected
false
Explanation
45 factors as 3^2 * 5; no matter how many times the charge is tripled from 1, it can only ever be a pure power of 3, and 45 has a leftover factor of 5, so the answer is false.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →