... 995 996 997 999Fun with math: Dividing one by 998001 yields a surprising result
21–30 of 99 posts
Re: Fun with math: Dividing one by 998001 yields a surprising result
#22I 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?
Re: Fun with math: Dividing one by 998001 yields a surprising result
#23http://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.Re: Fun with math: Dividing one by 998001 yields a surprising result
#24Re: Fun with math: Dividing one by 998001 yields a surprising result
#25There's no 998 (and it's not a rounding issue)! ... 995 996 997 999
... 95 96 97 99 00 01 02 ...
And extrapolating it to one digit, 1/81 gives 0.012345679012345679...Re: Fun with math: Dividing one by 998001 yields a surprising result
#26There's no 998 (and it's not a rounding issue)! ... 995 996 997 999
Re: Fun with math: Dividing one by 998001 yields a surprising result
#27Thanks 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.
Re: Fun with math: Dividing one by 998001 yields a surprising result
#28This 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