Description

Given an integer n, return true if it is a power of three. A number is a power of three if it can be expressed as 3^k for some non-negative integer k. Otherwise, return false.

Examples

Input:n = 27
Output:true
Explanation:

27 = 3³.

Input:n = 0
Output:false
Explanation:

0 is not a power of three. Powers of three are 1, 3, 9, 27, ...

Input:n = 9
Output:true
Explanation:

9 = 3^2, which is a power of three.

Input:n = 45
Output:false
Explanation:

45 = 9 * 5. Since 5 is not a power of 3, 45 is not a power of three.

Constraints

  • -2³¹ ≤ n ≤ 2³¹ - 1

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!