# Find the first digit of a number

I have seen this question but i could not find any answers.Let

A= a*b*c*d....   very huge multiplication

So what we can do take log(base 10) of number

log(A) = log(a)+log(b)+log(c).....
log(A) = S (summation of logs)

From here onward how can i find the first digit. I came to know that

Fist digit = Number after decimals in S which is close to log of (1..9)

Can you explain how to do that ?

Given the number $N$, compute $log_{10}(N)$, take the fractional part (lets denote that with $f$) and calculate $10^f$. Truncate $10^f$ to get the first digit of $N$.

Example :

$N=2^{64}$

$log_{10}(N)=19.2659$

$10^{0.2659}=1.84...$

First digit : $1$

In the case of $9\cdot 10^5$ for example, this method fails because $10^f=8.9999\cdots\$ (The number of $9's$ depends on the accuracy of $10^f$), but the correct answer is $9$. But the method will work well if not too many zeros follow the first digit.

Why does the method work ?

Let $s$ be the number with $10^s=N$. If $f$ is the fractional part of $s$ and $t$ the truncation of $s$, we have $N=10^s=10^{t+f}=10^t\cdot 10^f$. So we multiply $10^f$ with a number of the form $10^k$, so the first digit of $10^f$ is also the first digit of $N$.

• why it's working can u give me the intuition behind this – cxzczxc Jun 14 '16 at 8:25
• wow.. good approach – cxzczxc Jun 14 '16 at 8:43

Let us take an example.

Assume the product is, in scientific notation,

$$A=3.14159265\cdot10^8.$$

We can write the bracketing

$$3\cdot10^8\le A<4\cdot10^8,$$

and taking the decimal logarithm,

$$\log_{10}(3)+8\le\log_{10}(A)<\log_{10}(4)+8.$$

As the logarithm of a single digit is less than $1$, we can keep the fractional parts only and we have

$$\log_{10}(3)\le\{\log_{10}(A)\}<\log_{10}(4).$$

More generally, by comparing the fractional part of the logarithm of $A$ to the logarithms of the digits, you find where the leading digit of $A$ fits.