What's the longest repetend that can be created from a simple fraction?

What's the longest possible repeating decimal (repetend) that can be created from a fraction if:

• The numerator has to be less than or equal to 9,999
• The denominator has be less than or equal to 9,999?

I know the repeating decimal part can't exceed the denominator - 1. So the longest possible repeating decimal part has to be 9,998 or less.

The reason I want to know is to test an algorithm that I wrote which accepts fractions with numerators and denominators up to 9,999. The largest repeating decimal part I was able to create so far was 1/97 which equaled 0.[01030927 83505154 63917525 77319587 62886597 93814432 98969072 16494845 36082474 22680412 37113402 06185567] (96 repeating digits).

• Could you explain what you mean by the largest possible repeating decimal? Because all fractions will produce a repeating decimal and the largest would therefore be 9999/1 = 9999. Do you mean the longest period of repetition? – guest196883 Jan 27 '13 at 1:28
• I mean the longest period of repetition. For 1/97 I get 96 repeating digits. – user1822824 Jan 27 '13 at 1:30
• I'm looking for a fraction that will create a period of repetition of 9,998 repeating digits? – user1822824 Jan 27 '13 at 1:32
• If you want a fraction with a period of exactly $9998$, then you need to find a denominator which divides $10^{9998}-1$ and doesn't divide $10^r-1$ for any $r$, $1\le r\le9997$. Theory guarantees there are some, but they may have hundreds or thousands of digits. – Gerry Myerson Jan 27 '13 at 3:49
• The repeating part is called the repetend. You want to know what the longest possible repetend is. – steven gregory Nov 18 '16 at 3:14

The numerator doesn't matter (for this question), so you might as well let it be $1$. The denominator should be the largest prime under $10000$ which has $10$ as a primitive root. I don't know offhand what that prime is, but I'm sure such primes are tabulated and shouldn't be hard to locate.

The table at the Online Encyclopedia doesn't go far enough. There is an applet which claims to find these primes, but I couldn't make it work --- maybe you'll have better luck.

• I just did 1/9973 and got 0. --- 554 repeati – user1822824 Jan 27 '13 at 1:38
• I found this list of primes... primes.utm.edu/lists/small/10000.txt – user1822824 Jan 27 '13 at 1:39
• 1/9967 would be the largest, producing a period of 9966. – guest196883 Jan 27 '13 at 1:43
• @DoctorBatmanGod: Please don't make edits that change the meaning of the post, unless it is marked Community Wiki. – Rahul Jan 27 '13 at 1:52

1/9801= 0.010203040506070809010111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697990010203..., about 100 repeating digits

• since each number is represented by two digits (01, 02, 03...) and every number to 99 is represented, that's 99x2 + 1 (for the final zero). That's 199 repeating digits. – Madivad Dec 31 '14 at 11:32
• What is special about the numbers 9801, 998001, 99980001 ..? – phuclv Mar 23 '16 at 6:08
• @LưuVĩnhPhúc - $99^2, 999^2, 9999^2$? – steven gregory Nov 18 '16 at 4:02

You can find more details on on my main web page at “engert.us/erwin/Miscellaneous.html” where I have a listing of repeating digits for all odd numbers under 28,000. I also have a listing of prime numbers with how many repeating digits hey have in “engert.us/erwin/miscellaneous/Reciprocals%20of%20prime%20numbers.pdf. For your interest here a just a few of the numbers under 9,999 they are: 1/9871, 4935 1/9883, 4941 1/9887, 9886 1/9901, 12 1/9907, 4953 1/9923, 4961 1/9929, 1241 1/9931, 9930 1/9941, 1988 1/9949, 9948 1/9967, 9966 1/9973, 554 Erwin

1/9679 = 00010331645831180907118503977683645004649240624031408203326789957640252092158280814133691497055480938113441471226366360161173674966422151048662051864862072528153734889967971897923339187932637669180700485587354065502634569686951131315218514309329476185556359128009091848331439198264283500361607604091331749147639218927575162723421841099287116437648517408823225539828494679202396941832833970451492922822605641078623824775286703171815270172538485380721148879016427316871577642318421324516995557392292592209939043289596032648000826531666494472569480318214691600371939249922512656266143196611220167372662465130695319764438475049075317698109308812893893997313772083892964149188965802252298791197437751833867135034611013534456038846988325240210765574956090505217481144746358094844508730240727347866515135861142680028928608327306539931811137514206013017873747287942969315011881392705858043186279574336191755346626717636119433825808451286289905982022936253745221613803078830457691910321314185349726211385473705961359644591383407376795123463167682611840066122533319557805558425457175328029755139993801012501291455728897613389812997210455625581155078003926025415848744705031511519785101766711437131935117264180183903295795020146709370802768881082756483107759066019216861245996487240417398491579708647587560698419258187829321210868891414402314288666184523194544891001136481041429899783035437545200950511416468643454902365946895340427730137410889554706064676102903192478561834900299617729104246306436615352825705134827978096910837896476908771567310672590143609877053414608947205289802665564624444674036574026242380411199504081 (1613 digits? K.)

• This is not as good as 1/9967 cited in a comment to Gerry Myerson's answer. – Ross Millikan Nov 18 '16 at 3:09

This question is a variation of Problem 26 on Project Euler. As guest196883 pointed out in the comments "1/9967 would be the largest, producing a period of 9966."

Essentially, your question can be answered by finding the largest full repetend prime, p, smaller than 10,000. Referring to these primes The On-Line Encyclopedia of Integer Sequences® says:

Primes p such that the decimal expansion of 1/p has period p-1, which is the greatest period possible for any integer.

I used the following C++ program to check if the number 9967 is the largest full repetend prime smaller than 10,000 – you can test the program using C++ shell:

#include <iostream>

int main()
{
int denominator = 9999;
int max = 0;
int i, j, value, counter, p;
for (i = 7; i <= denominator; i += 2)
{
counter = 0;
value = 10%i;
j = denominator;
while (value != 1 && j > 0)
{
value *= 10;
value %= i;
counter++;
j--;
}
if (counter > max && j > 1)
{
max = counter;
p = i;
}
}
std::cout << p;
return 0;
}

And indeed, 9967 is the largest full repetend prime smaller than 10,000. So, the final answer to your question is that the longest repetend that can be obtained in a division between 2 integers smaller than 10,000 is 9966 decimals long. Any fraction of the form d/9967 will have a repetend this long if d is a non-zero integer that is not a multiple of 9967 – because... negative numbers.