You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: solution/0300-0399/0326.Power of Three/README_EN.md
+70-4Lines changed: 70 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,7 +62,11 @@ tags:
62
62
63
63
<!-- solution:start -->
64
64
65
-
### Solution 1
65
+
### Solution 1: Trial Division
66
+
67
+
If $n \gt 2$, we can continuously divide $n$ by $3$. If it's not divisible, it means $n$ is not a power of $3$, otherwise we continue dividing by $3$ until $n$ is less than or equal to $2$. If $n$ equals $1$, it means $n$ is a power of $3$, otherwise it's not a power of $3$.
68
+
69
+
Time complexity $O(\log_3n)$, space complexity $O(1)$.
0 commit comments