Power of Three
Return True if n equals 3 raised to some whole number power (1, 3, 9, 27, ...), otherwise False. Zero and negative numbers do not count.
Example 1
n 27
returns true
3 cubed.
Example 2
n 45
returns false
45 = 9 * 5, not a power of three.
Constraints
-231 <= n <= 231 - 1
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Math problems
- Power of TwoBeginner
- Product Minus Sum of DigitsBeginner
- Seconds to ClockBeginner
- Staircase of StonesBeginner
- Steps to Reduce to ZeroBeginner
- Sum of Consecutive PowersBeginner
- Sum of DivisorsBeginner
- Sum of MultiplesBeginner