Reputation: 2785
Today while going through a random video on youtube, I learn't about a very interesting law called Benford's law. I was wondering if it is possible to write a code to verify it for a^n.
I want to write a code that prints the first digit of 2^n where n is of order 10^5. Is it possible to write a code for it?
I know I haven't posted any code sample or shown any research effort.I am unable to think of any algorithm for it.
Upvotes: 1
Views: 396
Reputation: 24557
Use logarithms.
log_10(2) = 0.30102999566
log_10(2^100000) = 30102.999566
In other words, 2^100000 is a 30103-digit number, whose first digit can be found from the fractional part of this number:
10^0.999566 = 9.9900..
Upvotes: 4