All problems
1131EasyMathBit ManipulationRecursion

Is the Number a Power of Four

Tracked in this browser only
Write code

Trains the technique from

LeetCode 342Power of Four

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

Return true when the whole number n is a power of four, meaning n equals 4 raised to some whole power of zero or more.

Examples

Example 1

Input
n = 64
Output
true

Four multiplied by itself three times comes to 64.

Example 2

Input
n = 8
Output
false

Eight is a power of two but not of four: dividing it by four leaves two behind.

Example 3

Input
n = 0
Output
false

Every power of four is at least one, so nothing this small qualifies.

Constraints

  • -2^31 <= n <= 2^31 - 1

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def is_power_of_four(n: int) -> bool:
Java
public boolean isPowerOfFour(int n)
September 7
Apply