{"id":158,"date":"2024-01-25T02:23:27","date_gmt":"2024-01-25T02:23:27","guid":{"rendered":"https:\/\/thorshov.net\/?p=158"},"modified":"2024-01-25T03:54:30","modified_gmt":"2024-01-25T03:54:30","slug":"prime-reciprocals-repetends-and-repunits","status":"publish","type":"post","link":"https:\/\/thorshov.net\/index.php\/2024\/01\/25\/prime-reciprocals-repetends-and-repunits\/","title":{"rendered":"Prime Reciprocals, Repetends and Repunits"},"content":{"rendered":"\n<p>I was recently watching a numberphile video on <a href=\"https:\/\/www.youtube.com\/watch?v=DmfxIhmGPP4&amp;t=746s\" data-type=\"URL\" data-id=\"https:\/\/www.youtube.com\/watch?v=DmfxIhmGPP4&amp;t=746s\">YouTube<\/a>. Matt Parker explores a volume of work by William Shanks.   Shanks calclulated the digit length of the repetend for the reciprocals of thousands of prime numbers.  His work was carried out by hand in the mid to late 1800s.  <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"249\" src=\"https:\/\/thorshov.net\/wp-content\/uploads\/2022\/03\/image-1-1024x249.png\" alt=\"\" class=\"wp-image-163\" srcset=\"https:\/\/thorshov.net\/wp-content\/uploads\/2022\/03\/image-1-1024x249.png 1024w, https:\/\/thorshov.net\/wp-content\/uploads\/2022\/03\/image-1-300x73.png 300w, https:\/\/thorshov.net\/wp-content\/uploads\/2022\/03\/image-1-768x187.png 768w, https:\/\/thorshov.net\/wp-content\/uploads\/2022\/03\/image-1-1536x374.png 1536w, https:\/\/thorshov.net\/wp-content\/uploads\/2022\/03\/image-1-2048x498.png 2048w, https:\/\/thorshov.net\/wp-content\/uploads\/2022\/03\/image-1-1568x381.png 1568w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>Shanks&#8217; table of prime numbers adjacent to the number of repeating digits in its reciprocal<\/figcaption><\/figure>\n\n\n\n<p>A number is called prime if it is greater than 1 and has only 1 and itself as a divisor.   The first 10 prime numbers are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29.  The following is c# code finds all primes less than 2^32 or 4,294,967,296 and saves them to a primes.bin.<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:12px\"><code lang=\"csharp\" class=\"language-csharp\">private void DoIt(){\n    BuildPrimeList(uint.MaxValue);\n    BinaryWriter primeFile = new BinaryWriter(File.OpenWrite(\"primes.bin\"));\n    foreach(uint prime in m_PrimeList)\n       primeFile.Write(prime);\n    primeFile.Close();\n}\n \nprivate void BuildPrimeList(uint maxCandidate)\n{\n    m_PrimeList = new List&lt;uint&gt;();\n    m_PrimeList.Add(2);\n    for (uint i = 3; i &lt; maxCandidate; i+=2)\n       IsPrime(i);\n}\n\nprivate bool IsPrime(uint candidate)\n{\n    int maxFactor = (int)Math.Ceiling(Math.Sqrt(candidate))+1;\n    foreach (int prime in m_PrimeList){\n      if (candidate % prime == 0) return false;\n      if (prime &gt; maxFactor) break;\n    }\n    m_PrimeList.Add(candidate);\n    return true;\n}<\/code><\/pre>\n\n\n\n<p>The recipracol of a number n, is simply 1\/n and when this fraction is converted to a decimal there are either finite digits or an infinite number of digits that repeat after some time.  All prime numbers with the exception of 2 and 5 have decimal representations of their reciprocals containing infinite digits with repeating patterns.  Consider the following examples:<\/p>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\">\n<p>prime:  7<br>reciprocal:  1\/7<br>0.142857142857142857&#8230;<br>repeating digits:  6<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column\">\n<p>prime: 11<br>reciprocal: 1\/11<br>0.0909090909090909&#8230;<br>repeating digits: 2<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column\">\n<p>prime: 13<br>reciprocal: 1\/13<br>0.07692307692307692&#8230;<br>repeating digits:  6<\/p>\n<\/div>\n<\/div>\n\n\n\n<p>When the pages of Shanks&#8217; work appeared on the screen I noticed a relationship between some of the numbers.  Many of the primes had a repeating digit count that was only one less then the prime number itself.  Similar to 7 above.   Then I noticed that some had half the repeating digits of one less than prime.  <\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" src=\"https:\/\/thorshov.net\/wp-content\/uploads\/2022\/03\/image-2-1010x1024.png\" alt=\"\" class=\"wp-image-164\" width=\"426\" height=\"431\" srcset=\"https:\/\/thorshov.net\/wp-content\/uploads\/2022\/03\/image-2-1010x1024.png 1010w, https:\/\/thorshov.net\/wp-content\/uploads\/2022\/03\/image-2-296x300.png 296w, https:\/\/thorshov.net\/wp-content\/uploads\/2022\/03\/image-2-768x778.png 768w, https:\/\/thorshov.net\/wp-content\/uploads\/2022\/03\/image-2.png 1494w\" sizes=\"(max-width: 426px) 100vw, 426px\" \/><\/figure>\n\n\n\n<p>I paused the video and tested a few on the page and saw that each prime was one more than a multiple of the digit count.  I supposed that this might be true for all the numbers in his list.  Since I did not have his list available I decided to write the following code create a dictionary that would replicate his work.    This way I could perform a test.<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:12px\"><code lang=\"csharp\" class=\"language-csharp\">private uint RecipricolDigits(uint num, uint max)\n{\n   uint digitCount = 0;\n   List&lt;uint&gt; used = new List&lt;uint&gt;((int)max);\n   uint remainder = 1 % num;\n   while (!used.Contains(remainder) &amp;&amp; digitCount&lt;=max){\n     digitCount++;\n     used.Add(remainder);\n     remainder = (remainder*10) % num;\n     }\n\n   return digitCount;\n}<\/code><\/pre>\n\n\n\n<p>For each prime p&lt;1000 I found that the prime was infact one more than a multiple of the number of repeating digits.  I was curious if there might be a pattern to the multiples and decided to plot the against the prime number.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"464\" src=\"https:\/\/thorshov.net\/wp-content\/uploads\/2022\/03\/image-3-1024x464.png\" alt=\"\" class=\"wp-image-165\" srcset=\"https:\/\/thorshov.net\/wp-content\/uploads\/2022\/03\/image-3-1024x464.png 1024w, https:\/\/thorshov.net\/wp-content\/uploads\/2022\/03\/image-3-300x136.png 300w, https:\/\/thorshov.net\/wp-content\/uploads\/2022\/03\/image-3-768x348.png 768w, https:\/\/thorshov.net\/wp-content\/uploads\/2022\/03\/image-3-1536x696.png 1536w, https:\/\/thorshov.net\/wp-content\/uploads\/2022\/03\/image-3-2048x928.png 2048w, https:\/\/thorshov.net\/wp-content\/uploads\/2022\/03\/image-3-1568x711.png 1568w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>for each prime p&lt;1000 I plot c such that c*(number of repeating digits)+1=p<\/figcaption><\/figure>\n\n\n\n<p>After deciding there was no obvious pattern I took interest in the spike represented by the prime 271.   1\/271 in decimal form is 0.00369003690036900&#8230;. For a relatively large prime it only has 5 repeating digits and 54*(5)+1=271.   At this point I decided to google 271 and found a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Repunit\" data-type=\"URL\" data-id=\"https:\/\/en.wikipedia.org\/wiki\/Repunit\">wikipedia article<\/a> containing that number.<\/p>\n\n\n\n<p>This article discusses repunit numbers.   All digits of a repunit number are 1 therefor 1 , 11, 111, 1111, 11111, &#8230;&#8230; are repunit numbers.  271 appeared in a list of prime factors of the first thirty base 10 repunit numbers.  <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"360\" src=\"https:\/\/thorshov.net\/wp-content\/uploads\/2022\/03\/image-4-1024x360.png\" alt=\"\" class=\"wp-image-166\" srcset=\"https:\/\/thorshov.net\/wp-content\/uploads\/2022\/03\/image-4-1024x360.png 1024w, https:\/\/thorshov.net\/wp-content\/uploads\/2022\/03\/image-4-300x106.png 300w, https:\/\/thorshov.net\/wp-content\/uploads\/2022\/03\/image-4-768x270.png 768w, https:\/\/thorshov.net\/wp-content\/uploads\/2022\/03\/image-4-1536x541.png 1536w, https:\/\/thorshov.net\/wp-content\/uploads\/2022\/03\/image-4-2048x721.png 2048w, https:\/\/thorshov.net\/wp-content\/uploads\/2022\/03\/image-4-1568x552.png 1568w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>https:\/\/en.wikipedia.org\/wiki\/Repunit<\/figcaption><\/figure>\n\n\n\n<p>Then I started to notice that all of the prime factors in the table had a low number of repeating digits within the decimal representation of its reciprocal.  If one were to thumb through Shanks&#8217; pages these repunit factors would definitely stand out as having few repeating digits.  At this point I scripted some code that would calculate upto 265371653 rows of Shanks&#8217; data and output a list ordered by the repeating digit count.  The following is a partial list of primes in assending order of repeat counts for their reciprocals. <\/p>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\">\n<pre class=\"wp-block-code\" style=\"font-size:16px\"><code lang=\"csharp\" class=\"language-csharp\">3         1\n11        2\n37        3\n101       4\n41        5\n271       5\n7         6\n13        6\n237       7\n4649      7<\/code><\/pre>\n\n\n\n<p><\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column\">\n<pre class=\"wp-block-code\" style=\"font-size:16px\"><code lang=\"csharp\" class=\"language-csharp\">73          8\n137         8\n333667      9\n9091        10\n21649       11\n513239      11\n9901        12\n53          13\n79          13\n265371653   13<\/code><\/pre>\n<\/div>\n\n\n\n<div class=\"wp-block-column\">\n<pre class=\"wp-block-code\" style=\"font-size:16px\"><code lang=\"csharp\" class=\"language-csharp\">909091        14\n31            15\n2906161       15\n17            16\n5882353       16\n2071723       17\n19            18\n52579         18\n3541          20\n27961         20<\/code><\/pre>\n\n\n\n<p><\/p>\n<\/div>\n<\/div>\n\n\n\n<p>I was amazed and excited to see these numbers reflecting exactly those red numbers in the repunit factorization table from above!   As the repunit numbers increase, so does the order that new prime factors appear!  3 being the only exception.   I don&#8217;t have the computing power to test all primes up to numbers as high as 5363222357 and beyond in a timely matter, but even now as I write this blog I am noticing that the repeating digit count represents the repunit sequence number for which the prime will first appear!<\/p>\n\n\n\n<p>R1 = 1<br>R2 = 11 = <strong>11<\/strong>  (1\/11 has 2 repeating digits)<br>R3 = 111 = 3 \u00b7 <strong>37<\/strong> (1\/37 has 3 repeating digits)<br>R4 = 1111 = 11 \u00b7 <strong>101<\/strong>  (1\/101  has 4 repeating digits)<br>R5 = 11111 = <strong>41 \u00b7 271<\/strong>   (1\/41 and 1\/271 have 5 repeating digits)<br>R6 = 111111 = 3 \u00b7 <strong>7<\/strong> \u00b7 11 \u00b7 <strong>13<\/strong> \u00b7 37 (1\/7 and 1\/13 have 6 repeating digits)<br>R7 = 1111111 = <strong>239<\/strong> \u00b7 <strong>4649<\/strong> (1\/239 and 1\/4649 have 7 repeating digits)<br>R8 = 11111111= 11 \u00b7 <strong>73<\/strong> \u00b7 101 \u00b7 <strong>137<\/strong> (1\/73 and 1\/137 have 8 repeating digits)<br>R9 = 111111111 = 3<sup>2<\/sup> \u00b7 37 \u00b7 <strong>333667<\/strong> (1\/333667 has 9 repeating digits) <br>\u22ee<\/p>\n\n\n\n<p class=\"has-huge-font-size\">PAUSE!!!!! Stop writing this blog!<\/p>\n\n\n\n<p>What? Why stop writing the blog? This is almost interesting for God&#8217;s sake!  It is years later now and I have resolved to continue adding content to my site so now I will explain.   <\/p>\n\n\n\n<p>I was so excited that I might have discovered something original.   What would it have felt like to sail the ocean blue and discover a new world?  How would it feel when you found out you weren&#8217;t the first to discover it?  I think this feeling has become common among many of us in the digital world.  The experience of starting down what you percieve to be an original road only to realize you are within someone elses old tracks.  There is a disappointment associated with learning that an idea is not original. This createive letdown caused me to put it all away and stop writing and stop exploring the repunit\/prime recipricol relationship.  As a result there would be no more insight, even if it was original, and there would be no more blog.  <\/p>\n\n\n\n<p>I discovered that my idea wasn&#8217;t original when reading a rather demoralizing sentence the history section of the aforementioned <a href=\"https:\/\/en.wikipedia.org\/wiki\/Repunit\">Wikipedia article<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-verse has-text-color\" style=\"color:#e2b47f\">\"It was found very early on that for any prime p greater than 5, the period of the decimal expansion of 1\/p is equal to the length of the smallest repunit number that is divisible by p.\"<\/pre>\n\n\n\n<p>I was able to glean the above &#8220;on my own&#8221; very quickly considering the youtube video and ensuing Wikipedia article were at my disposal, as well has having the power of a programming language and modern PC.  The road to my &#8220;high&#8221; was quick and so was the fall.   <\/p>\n\n\n\n<p>William Shanks spent a lifetime creating his tables and I admire his dedication to such a tedious task and believe he must have found peace through his accomplishments.  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was recently watching a numberphile video on YouTube. Matt Parker explores a volume of work by William Shanks. Shanks calclulated the digit length of the repetend for the reciprocals of thousands of prime numbers. His work was carried out by hand in the mid to late 1800s. A number is called prime if it &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/thorshov.net\/index.php\/2024\/01\/25\/prime-reciprocals-repetends-and-repunits\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Prime Reciprocals, Repetends and Repunits&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":165,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10,9],"tags":[],"_links":{"self":[{"href":"https:\/\/thorshov.net\/index.php\/wp-json\/wp\/v2\/posts\/158"}],"collection":[{"href":"https:\/\/thorshov.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thorshov.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thorshov.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thorshov.net\/index.php\/wp-json\/wp\/v2\/comments?post=158"}],"version-history":[{"count":9,"href":"https:\/\/thorshov.net\/index.php\/wp-json\/wp\/v2\/posts\/158\/revisions"}],"predecessor-version":[{"id":187,"href":"https:\/\/thorshov.net\/index.php\/wp-json\/wp\/v2\/posts\/158\/revisions\/187"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thorshov.net\/index.php\/wp-json\/wp\/v2\/media\/165"}],"wp:attachment":[{"href":"https:\/\/thorshov.net\/index.php\/wp-json\/wp\/v2\/media?parent=158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thorshov.net\/index.php\/wp-json\/wp\/v2\/categories?post=158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thorshov.net\/index.php\/wp-json\/wp\/v2\/tags?post=158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}