If `N`

is a power of `3`

:

- It follows that
`3^X == N`

- It follows that
`log (3^X) == log N`

- It follows that
`X log 3 == log N`

- It follows that
`X == (log N) / (log 3)`

- For the basis to hold,
`X`

must be an integer.

However, due to the fact that log(3) cannot be precisely represented on a binary computer; X is considered an integer if its decimal component falls within a guard range of `+/-0.00000000000001`

. Static imports for `log`

, `abs`

and `rint`

from `java.lang.Math`

.

```
public boolean isPowerOfThree(int n) {
double a = log(n) / log(3);
return abs(a - rint(a)) <= 0.00000000000001;
}
```