Where I started

Need to handle big numbers in Excel

Units fore and aft puzzle
There was a puzzle in the Enigma column of the "New Scientist" magazine that caught my interest. It went roughly like this. 77 can be multiplied by 23 by adding a 1 at the front and back to give 1,771. Similarly, 137 can be multiplied by 83 in the same way to give 11,371. What is the biggest prime number multiplier for which this trick can be done?

Range of possible answers
I looked for the range of possible answers by doing some examples in a spreadsheet.


starting numberresultmultiplier
1111111.00
111,111101.00
10111,011109.02
1,001110,011109.90
10,0011,100,011109.99
100,00111,000,011110.00
1,000,001110,000,011110.00
   
919121.22
991,99120.11
99919,99120.01
9,999199,99120.00
99,9991,999,99120.00
999,99919,999,99120.00
9,999,999199,999,99120.00


The biggest multiplier is roughly 110. But the result ends in 1 so both the starting number and the multiplier must be odd numbers. Could the biggest multiplier be 109?

What's happening to the starting number?
Two things happen:

a) it gets multiplied by 10 as all its digits are shifted one place to the left and
b) we add a number such as 100000001

100000001 + (startNo * 10) = (startNo * n)

100000001 = startNo * (n - 10)

n = the multiplier we are looking for

So we are looking for a number like 100000001 that is divisible by (n – 10). If the highest prime multiplier was 109 we would need to find a number like 100000001 that is divisible by 99. This is not possible as 99 has a factor of 3. The number like 100000001 will never be divisible by 3 as the sum of its digits is 2.

Could it be 107?
The next biggest possibility we could look for is 107.
Is there a number like 100000001 that is divisible by 97?

It is easy to use Excel on numbers up to 100,000,000,000,001 but then it overflows.

Bigger numbers in Excel
I wrote the big number in the worksheet: one digit per cell. (division.xls – see my division page) Then I wrote a function that did long division and told me the remainder. (Very simple: about 10 lines of code.) By adding zeros in the middle of the number in the worksheet and watching what happened to the remainder, I found what I was looking for – a number that was divisible by 97. The number had 47 zeros in the middle. I divided that number by 97 to obtain the starting number.

Check the result
As a final check, I added a 1 at the front and back and divided by 107. I was delighted – exactly what I wanted – plus considerable satisfaction from playing with numbers nearly 50 digits long in Excel.

Interesting things to do
There are lots more numbers like this. Make a collection of them and look at the patterns.

What about adding a different digit fore and aft? What happens then?

What is the second number that can be multiplied by 107 in this way? Clue: how long is the pattern of decimals that the fraction 1/97 has?

*home