Republic of Mathematics blog

How do you find a power of 2 that begins with a 9?

Posted by: Gary Ernest Davis on: November 13, 2010

The problem of finding a power of 2 that begins with a 9 was posed in the recent #mathjams conference in the UK.

I tweeted:

republicofmath 2^n begins with 9 for n = 53, 63, 73, 83, 93, 156, 166, 176, 186, 249, 259, 269, 279, 289, 352, 362, 372, 382, 445, 455, 465 … #MathsJam


Following my tweet Barb Lynch asked:

Stelladuma @republicofmath How did you get the solutions for 2^n beginning with 9?
My answer was short and straight to the point (I had used Mathematica) but not explanatory:
republicofmath @Stelladuma 2^n beginning 9? #Mathematica: L = {}; Do[If[IntegerDigits[2^n][[1]] == 9, L = Append[L, n], L = L], {n, 1, 750}]; L #mathsjam
Barb Lynch, from Northeast Ohio, USA, is a teacher of algebra 1 and geometry to G/T middle school students. Chances are Barb does not have an available copy of Mathematica, and it’s highly likely  her students do not have access to Mathematica even if she does.
So, if we are to adopt a computational solution to finding the powers of 2 that begin with 9, it would be handy to have another computational engine that students did have access to.
Enter a spreadsheet.
I will use Excel, but an open source spreadsheet, including that on Google Docs will do.
All we need from a spreadsheet is built-in functions for:
  • logarithms to the base 10
  • finding the whole number part of a decimal number
  • the ability to form powers.
All spreadsheets can do these things.
The idea is that we will generate a list of powers of 2 and examine that list to see which entries begin with a 9.
The one trick we need is to figure out how to extract the leading digit from a number such as “123′ when it is written in the spreadsheet.
Of course as human beings we just look to the left and speak the digit.
The question is: how do we instruct a spreadsheet to to do that?
The answer, it turns out, is surprisingly easy, using the miraculous powers of indices (otherwise known by the mysterious name of “logarithms”).
Here’s the idea:
  • To figure out how many powers of 10 are involved in a number such as 123, we take the logarithm, base 10, of the number. This makes sense because log_{10}(10^k)=k. So, for example, log_{10}(123) \approx 2.089905111.
  • To figure out what whole number of powers of 10 are involved in a number, such as 123 we drop the fractional bit of log_{10}(123)=2.089905111 to get 2. To do this in the spreadsheet we use the function “int” which takes the integer part of a decimal number.
  • Now we have now that 123 is in the range 10^2 we need to divide by this number to figure how many of these powers of 10 we have. So we divide 123 by 10^2 to get 1.23.
  • Now we are pretty much there: if we take the integer part of this number, using “int” we get 1. Voila! We have the leading digit of our number.
So here’s a how we might implement this in a spreadsheet (click on the image to enlarge it):
What do these spreadsheet formulas mean?
  1. In the first column we are just creating a list of integers 1, 2, 3, 4, … by beginning with 1 and adding 1 at each step.
  2. In the second column we are forming 2^n where n is the corresponding entry in the first column.
  3. In the third column we are taking the logarithm, base 10, of the corresponding number in the second column.
  4. In the fourth column we are finding the whole number part of the decimal number in the third column.
  5. In the fifth column we are dividing the corresponding number in the second column (2^n) by 10 raised to the power in the fourth column.
  6. In the sixth column we are taking the whole number part of the decimal number in the fifth column.
  7. In the seventh column we asking the spreadsheet to say “YES” if the number in the sixth column is 9 (and “NO”otherwise)
When we do this without displaying formulas, ax I have done above, but just showing  numbers, we see that a “YES” first appears at n = 53, and another “YES” appears soon after at n = 63 (click on the image to enlarge it):
That’s it, from a computational perspective.
Pretty soon a spreadsheet will not be able to accurately calculate large powers of 2, so another computational engine needs to be used. That’s a story for another time.

8 Responses to "How do you find a power of 2 that begins with a 9?"

You can also do this without logarithms. Just multiply by 2 each time, and divide by 10 when the result exceeds 10. (This could be useful if students have not studied logarithms yet.)

Thanks Dave. Always good to find a more direct, less complicated, way of doing things.

Another fun observation is how many of those powers of 2 start with the digit 1: 30.1% of them in the long run. Then 17.6% start with 2, and so on. If you have a big slide rule around, you can show them the same proportions on the C or D scale. The same (first digit) thing works with our beloved Fibonacci numbers, and most any geometric sequence.

Dan have you blogged about this? Will you? Have you seen James Tanton’s YouTube video on Benford’s law?

You can also handle the larger powers of 2 by eliminating that column and only using the logarithms: n * log(2) rather than log(2^n). That ought to have sufficient accuracy at least up to 2^100000 or something in that neighborhood.

Here’s a solution in Python. Somewhat similar to the Mathematica solution, but Python is totally free and available to anyone.

>>> [n for n in range(1, 1001) if str(2**n)[0] == ‘9’]
[53, 63, 73, 83, 93, 156, 166, 176, 186, 249, 259, 269, 279, 289, 352, 362, 372, 382, 445, 455, 465, 475, 485, 548, 558, 568, 578, 641, 651, 661, 671, 734, 744, 754, 764, 774, 837, 847, 857, 867, 930, 940, 950, 960, 970]

Thanks for this Michel. I would very much like to get secondary mathematics teachers interested in using Python, particularly for computational explorations such as this.

Great post, thanks Michel for pointing me to this. I love seeing ways of using technology that imparts a valuable programming skill while giving students a deeper understanding of math (e.g. that 91 is 9*10+1).

I have blogged a bit about this here but I definitely need to give some more examples like this post.

Leave a Reply