Ctrl K

Only Threes Multiplied

Easy
You are given an integer n. Return True if n equals 3ᵏ for some integer k ≥ 0, and False otherwise. Try to solve it without loops or recursion.
Example 1
n=81 → True

81 = 3⁴.

Example 2
n=0 → False

No power of three equals zero.

Example 3
n=-9 → False

Powers of three are positive, so a negative number never qualifies.

Constraints
  • -2³¹ ≤ n ≤ 2³¹ - 1
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsOnly Twos Multiplied EasyOnly Fours Multiplied EasySum of the Two Before EasyA String That Copies Itself EasyAdding Digit Lists Medium
loading Python…
Input
n=81
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 72 tests on the server, hidden ones included.