Determine whether a number is a power of 3

98 Views Asked by At

Why does $\frac{\log(n)}{\log(3)}$ being an integer determine whether $n$ is a power of three?

While doing some programming exercises I came across this problem and the above formula was a proposed solution. Can someone explain to me why this is the case?

3

There are 3 best solutions below

0
On

Because $n = 3^k$ for some $k \in \mathbb Z$ iff $k = \log_3 n = \frac{\lg n}{\lg 3} \in \mathbb Z$.

2
On

Assume $\frac{\ln n}{\ln 3}=k$ with $k$ being an integer.

Then $\ln n=k\ln 3=\ln 3^k$ and so $n=3^k$

0
On

There is a change of base formula for logarithms : $$\log_b(x)=\frac{\log_d(x)}{\log_d(b)}$$Also note the following formula to relate logs to exponents:$$\log_b(b^x) = x$$ this since for any base $b$, $\log_3(n)=\frac{\log_b(n)}{\log_b(3)}$, and and power of $3$ will be of the form $3^x$, we have:$$\frac{\log(3^x)}{\log(3)}=\log_3(3^x)=x$$

Therefore, if $n$ is put into the formula, you will recieve a number $x$ such that $n=3^x$. If $x$ is an integer, then you know that $n$ is a power of $3$.