First digit of $3^n$

76 Views Asked by At

$3^n$ begins with 1 for some non negative integers $n$ Find the number of such integers $n$ where $0\leq n\leq 1000$ Example $3^0=1,3^9=19683$
We can write number in the form $a_0+10a_1+\dots+10^ma_m$ the coefficient $a_m$ should be $1$. Is it right approach to solve?

1

There are 1 best solutions below

2
On

The simple approach is just to compute them. If you have an arbitrary precision system, you can get the largest power of $10$ less than $3^n$ by taking the floor of $\log_{10}(3^n)$. Call it $k$. The first digit of $3^n$ is $\left\lfloor \frac {3^n}{10^k}\right\rfloor$ Unfortunately $3^n$ will overflow if you use normal computer numbers.

The solution is to use the logarithm. $\log_{10}3^n=n\log_{10}3$. If the fractional part of this is between $0$ and $\log_{10}2$, the first digit is $1$. The integer part will be the $k$ from above, and we will have $10^k \lt 3^n \lt 2\cdot 10^k$