top | item 3514721

Fun with math: Dividing one by 998001 yields a surprising result

754 points| kenver | 14 years ago |iheartchaos.com | reply

90 comments

order
[+] psykotic|14 years ago|reply
There's some sleight of hand here. Not all the digits are exactly right. Look how it skips from 997 to 999:

http://www.futilitycloset.com/2012/01/08/math-notes-76/

Here's the math. Suppose you want a unit fraction 1/n with decimals that cycle through the 4-digit sequence abcd. Multiply by 10^4 to shift abcd into integer position, leaving repeating copies after the decimal point:

    10^4/n = abcd + 1/n
Solving for n gives n = (10^4 - 1) / abcd.

More generally, if you want to get a cycle equal to the d digits of an integer k, you want n = (10^d - 1) / k.

However, this only gives a true unit fraction when k divides 10^d - 1, so that n is an integer. Otherwise you are forced to truncate n and getting an approximate version of the cycle.

That's exactly what happened here: 10^d - 1 is not divisible by the integer 001002...998999.

Here's a small Python program that will generate the unit fraction given the number of digits to cycle through:

    import sys

    n = int(sys.argv[1])
    s = ''.join(("%0" + str(n) + "d") % (i,) for i in range(10**n))
    print "1/%d" % ((10**len(s) - 1) / int(s),)
Usage:

    $ python magic.py 3
    1/998001
    $ python magic.py 4
    1/99980001
This has just the right flavor for a Project Euler problem.
[+] bdg|14 years ago|reply
I just want to know I appreciate you posting this. Some people might be interested in "wow math sure can do some funky stuff", but others like myself really want to know why. I figure that's also covers a sizable group of us here on Hacker News.
[+] chadzawistowski|14 years ago|reply
It's a bit sneaky to say it generates all three-digit numbers when 998 clearly isn't there, but as onedognight pointed out below, the leading 1 from the 1000 which follows 999 will cause 999 to overflow into 1000, which turns the 998 into a 999.
[+] hashfold|14 years ago|reply
love the math. thanks for sharing.
[+] fryguy|14 years ago|reply
A simple way to figure out how this works is to figure out another way to write it out. For the simpler case (1/9801) = 0.00010203...

      0.00
    + 0.0001
    + 0.000002
    + 0.00000003
      ...
    --------------
Each row is equal to x, but shifted over 2x digits. This is the same as dividing by 10^x. This simplifies to the formula:

    sum k=0 to infinity: k/(10^k)
This is fairly easily calculable, and results in 1/9801. Try it yourself on wolfram alpha: http://www.wolframalpha.com/input/?i=%28sum_%28k%3D1%29%5Ein...
[+] tylerneylon|14 years ago|reply
The general any-number-base-b rule here (as others have noticed in base 10^k) is that

1/(b-1)^2 = 0.0123456... (where '1', '2'.. are base b digits).

The original post is this fact in base 1000.

Proof for any base: 1/(b-1) = 1/b + 1/b^2 + 1/b^3 + .. = 0.11111.. (base b).

So 1/(b-1)^2 = 0.11111.. * (1/b + 1/b^2 + 1/b^3 + ...) = 0.012345... QED.

Richard Feynman beat us all to the punch here by noticing that 1/243 = 0.004115226337..., a fact which he wrote in a letter from a secret lab to someone in the outside world, and which put him under suspicion of sending secret messages! That gem of a fraction turns out to be a result of the above stuff as 1/243 = 111 * (1/999^2) + 4/999.

Here's a slightly more detailed explanation:

http://tylerneylon.com/b/archives/51

[+] saraid216|14 years ago|reply
I just want to repeat bdg's appreciation for the people who are explaining the actual theory, which is the interesting part. Funky results from arbitrary arithmetic is just a step short of numerology and while it's nifty in a stage magic kind of way, it's a little sad overall when you have no idea why that's the way it is.
[+] archgoon|14 years ago|reply
This can be seen in python with (I had to dig into the docs for this, so here are the fruits of my labor :) )

    import decimal

    decimal.getcontext().prec=1000
    dec = decimal.Decimal(1)/decimal.Decimal(998001)
    
    #now doctor it up to see the numbers
    strdec = str(dec)[2:] #chop off the '0.'
    nums = zip(strdec[::3],strdec[1::3],strdec[2::3])
    print nums
[+] boredguy8|14 years ago|reply
The period is 2997, so set precision to 2997 if you want to see the repeat. Also, "998" doesn't appear 'in sequence' (it obviously appears as 97[9 98]0 981).
[+] VMG|14 years ago|reply
echo "scale=3000; 1/998001" | bc
[+] mkmk|14 years ago|reply
I don't have a python shell available... what happens after 999?
[+] wtn|14 years ago|reply
In ruby (irb):

require 'bigdecimal'; BigDecimal.new(1).div(998001, 2997)

[+] phzbOx|14 years ago|reply
You've got an extra ) on the 'nums = .....'
[+] jerfelix|14 years ago|reply
... and 1/9999999800000001 = .00000000 00000001 00000002 00000003 00000004 00000005 00000006 ... 99999996 99999997 99999999 ...repeating

Basically, the pattern is 1 over some number of 9s, followed by an 8, followed by the same number of 0s, followed by a 1.

So, 1/81, 1/9801, 1/998001, 1/99980001, 1/9999800001, etc.

[+] xuki|14 years ago|reply
it's 9x9, 99x99, 999x999, 9999x9999,....
[+] kenver|14 years ago|reply
I was searching for some iOS documentation and found this and it's totally ruined my productivity!

Can anyone explain why it repeats in this way, or link to a place that has an explanation?

[+] knerd83|14 years ago|reply
For x < 1, 1 + 2x + 3x^2 + 4x^3 + ... converges to 1/(1-x)^2. When x = 0.001, you get 1/.999^2 = 1000000/998001 = 1.002003004005...
[+] deltasquared|14 years ago|reply

  ;Here is my version in Common Lisp
  ;Supply your own flatten function
  ;or borrow one from let-over-lambda or something
  ;http://letoverlambda.com/lol.lisp

  (defun long-div (dividend divisor depth)
    (cond
     ((> depth 0)
      (flatten (list
                (truncate (/ dividend divisor))
                (long-div (* 10 (mod dividend divisor))     
                 divisor (- depth 1)))))
     (t ())))
[+] slamdunc|14 years ago|reply
Thanks for posting. I'm trying to keep a collection of these type of things so that when she's ready, it'll be another tool to get/keep my daughter excited about math.
[+] skystorm|14 years ago|reply
Care to share? Would be handy to have for my daughter... :)
[+] adeelk|14 years ago|reply
Make sure you show her Gauss’s trick for summing arithmetic series.
[+] onedognight|14 years ago|reply
There's no 998 (and it's not a rounding issue)!

    ... 995 996 997 999
[+] onedognight|14 years ago|reply
It's because the 1000 will end up adding one to the 999 which becomes 1000 which adds one to 998.
[+] kghose|14 years ago|reply
Yes, that is funky.

  def long_div(x,y,N=10):
    """Given two integers x and y, return us the N digits of x/y."""
    #First work out the integer part
    x = int(x)
    divisor = y = int(y)
    quotients = [x/y]
    dividend = x % y
    for digit in range(N):
      dividend *= 10
      quotient = dividend/divisor
      dividend = dividend%divisor
      quotients.append(quotient)
  
    return quotients
  
  def pretty_print(quotients, G=3):
    """Pretty print quotients by grouping digits by 3."""
    strp = ''
    cnt = 1
    for n in quotients[1:]:
      strp += str(n)
      cnt +=1
      if cnt > G:
        print strp
        strp = ''
        cnt = 1
  
  
  quotients = long_div(1,998001,N=3000)
  pretty_print(quotients,G=3)
[+] tspiteri|14 years ago|reply
And even the suggested 1/9801 for two digits produces no 98

    ... 95 96 97 99 00 01 02 ...
And extrapolating it to one digit, 1/81 gives

    0.012345679012345679...
[+] jeffcapeshop|14 years ago|reply
you could always do 1/99980001 - that would have a 0998
[+] dimitar|14 years ago|reply
Some fun that can fit on a poket calculator:

12345679 * 9 = 111111111

12345679 * 18 = 222222222

12345679 * 27 = 333333333

12345679 * 36 = 444444444

12345679 * 45 = 555555555

12345679 * 54 = 666666666

12345679 * 63 = 777777777

12345679 * 72 = 888888888

12345679 * 81 = 999999999

12345679 * 999999999 = 12345678987654321

[+] grusk|14 years ago|reply
The way I was introduced to this was as a math trick: Pick a number 1-9, multiply by 9, then 12345679, and you get a string of whatever number you picked.

Also, pick any three-digit number, multiply by 7, 11, and 13 (or 1001), and you get your three-digit number repeated twice.

[+] buddydvd|14 years ago|reply
And this too: 111111111111111111111111111 / 9 = 12345679012345679012345679
[+] reedcat|14 years ago|reply
My productivity for today went downhill! :)

Love the trick with how this can be done via differentiating the equation:

1 + r + r^2 + ... = 1/(1-r)

[+] liljimmytables|14 years ago|reply
Slightly off-topic, but it bugs me that the article feels obliged to contain a picture of the number. Firstly, why the hell would you want to display plain text as a picture? Secondly, if I click through to the source, I get a slightly better picture. Did IHC take a photo of the original website with their phone camera and upload it? Mind is boggling. Encouraged by the better quality picture on geekosystem I decided to click through to THEIR source. And there's a plaintext version. Kudos to <a href="http://www.futilitycloset.com/2012/01/08/math-notes-76/<...; for having a modicum of common sense.
[+] jbdevon|14 years ago|reply
Also, 1/4999 yields the sequence of square numbers.
[+] tspiteri|14 years ago|reply
It's really powers of 2, not square numbers. That is, 2^x, not x^2.