Title: [FEATURE]: The Repunit theorem · Issue #1866 · TheAlgorithms/JavaScript · GitHub
Open Graph Title: [FEATURE]: The Repunit theorem · Issue #1866 · TheAlgorithms/JavaScript
X Title: [FEATURE]: The Repunit theorem · Issue #1866 · TheAlgorithms/JavaScript
Description: Motivation Numbers formed by repeating digits or repeating blocks—such as 111111, 424424, or structures like 10ⁿ + 1 (e.g., 100000001)—follow predictable patterns in number theory. These patterns are not random; they arise from the multi...
Open Graph Description: Motivation Numbers formed by repeating digits or repeating blocks—such as 111111, 424424, or structures like 10ⁿ + 1 (e.g., 100000001)—follow predictable patterns in number theory. These patterns a...
X Description: Motivation Numbers formed by repeating digits or repeating blocks—such as 111111, 424424, or structures like 10ⁿ + 1 (e.g., 100000001)—follow predictable patterns in number theory. These patterns a...
Opengraph URL: https://github.com/TheAlgorithms/JavaScript/issues/1866
X: @github
Domain: redirect.github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[FEATURE]: The Repunit theorem","articleBody":"### Motivation\n\nNumbers formed by repeating digits or repeating blocks—such as 111111, 424424, or structures like 10ⁿ + 1 (e.g., 100000001)—follow predictable patterns in number theory. These patterns are not random; they arise from the multiplicative order of 10 modulo a prime.\n\nRight now, we treat these numbers as arbitrary integers, which leads to three core problems:\n\n1. Missing mathematical behavior\n\nRepeated-digit numbers have a very specific factorization rule (e.g., 100000001 being divisible by 17). Without modeling the underlying theorem, our current logic either:\n- gives no insight into why the divisibility works,\n- or forces us to compute divisibility using naive methods that scale poorly.\n\n2. Inconsistent patterns in code\n\nBecause these numbers are treated on a case-by-case basis, any function that needs to handle:\n- repunits (111…1),\n- repeated digits (777777),\n- repeated blocks (XYZXYZ),\n- or cyclotomic structures (10ⁿ ± 1),\n\nends up re-implementing partial logic, often incorrectly or inefficiently. Bringing this into a unified mathematical rule improves maintainability and correctness.\n\n3. Huge performance waste for large repeated patterns\n\nRepeated-digit integers can be extremely large (sometimes more than a million digits long).\n\nUsing the multiplicative-order approach lets us compute divisibility using O(log n) modular arithmetic and without building the actual number at all.\n\nWith this algorithm in place, once the multiplicative order is part of the system, it unlocks:\n\n- fast repunit divisibility checks,\n- systematic analysis of repeated-digit numbers,\n- handling of cyclotomic expressions,\n- better support for prime testing involving decimal periodic.\n\nI believe this will be a good one to tackle, given that it's an unresolved problem in number theory.\n\n### Examples\n\n\nThese examples show actual numbers, their patterns, and the mathematical reason they’re divisible by certain primes.\n\n\n#### **1. Classic example: 100000001 is divisible by 17**\n\n```\n100000001 ÷ 17 = 5882353\n```\n\nWhy?\n\n`100000001 = 10⁸ + 1`\nThe multiplicative order of 10 modulo 17 is **8**, meaning:\n\n```\n10⁸ ≡ 1 (mod 17)\n```\n\nSo:\n\n```\n10⁸ + 1 ≡ 2 (mod 17)? No → but 10⁸ ≡ -1 (mod 17)\n```\n\nActually:\n\n```\n10⁸ ≡ -1 (mod 17)\n```\n\nTherefore:\n\n```\n10⁸ + 1 ≡ 0 (mod 17)\n```\n\n---\n\n#### **2. Repeated block example: 424424**\n\nBlock: `424`\nRepeated twice → total structure: `424424`\n\nDivisible by:\n\n```\n7, 11, 13 → because 1001 = 7 × 11 × 13\n```\n\nWhy?\n\n`424424 = 424 × 1001`, and:\n\n```\n1001 = 10³ + 1 = (10³ - 1)/9 × 9\n```\n\nThe fact that 1001 factors into 7, 11, and 13 comes from the multiplicative order of 10 modulo those primes.\n\n---\n\n#### **3. Repunit example: 111111**\n\n`111111` is `6` repeated digits of `1`.\nIt equals:\n\n```\n111111 = (10⁶ − 1) / 9\n```\n\nDivisible by:\n\n```\n3\n7\n11\n13\n37\n```\n\nWhy these primes?\n\nBecause the multiplicative order of 10 modulo each of those primes divides 6.\nFor example:\n\n* ord₁₁(10) = 2 → and 2 divides 6\n* ord₃₇(10) = 3 → and 3 divides 6\n* ord₇(10) = 6 → and 6 divides 6\n\nSo all of them divide `111111`.\n\n---\n\n#### **4. Repeated digit example: 999999999 (9 repeated 9 times)**\n\nThis is:\n\n```\n999,999,999 = 9 × 111,111,111\n```\n\nAnd `111,111,111` has divisors:\n\n```\n3\n37\n333667\n```\n\nAgain, it is determined by which primes have multiplicative order dividing 9.\n\n---\n\n#### **5. Three-block repeated pattern: XYZXYZXYZ**\n\nExample: `123123123`\n\nThis is:\n\n```\n123 × 1,001,001\n```\n\nPrime factors of 1,001,001:\n\n```\n1,001,001 = 7 × 11 × 13 × 101 × 109\n```\n\nAll these primes divide the repeated-block number because their orders divide 3×3.\n\n---\n\n#### **6. Palindromic power example: 10⁶ − 1 = 999999**\n\nDivisible by:\n\n```\n9 → trivial because it's 9 repeated digits \n37 \n3 \n27 \n```\n\nThe factor `37` is the famous one here because:\n\n```\n999 = 27 × 37\n```\n\nwhich again is tied to the order of 10 modulo 37 (which is 3).\n\n---\n\n#### **7. Full reptend prime example**\n\nA prime is \"full reptend\" in base 10 if the order of 10 mod p is p−1.\n\nExample:\n\n```\n7 is a full reptend prime.\n10 has order 6 mod 7.\n```\n\nThis is why:\n\n```\n1/7 = 0.142857142857… (repeats every 6 digits)\n```\n\nand why repunit length = 6.\n\n\n\n\n### Possible workarounds\n\n_No response_\n\n### Additional information\n\n_No response_","author":{"url":"https://github.com/ridge-kimani","@type":"Person","name":"ridge-kimani"},"datePublished":"2025-12-11T11:19:04.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/1866/JavaScript/issues/1866"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:1974534c-80ec-2aa9-1f08-b5b0df4b4143 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D918:2A6D10:24432C8:2F109BF:696B55FC |
| html-safe-nonce | 388c8cf6debb3715e175e94851e4e6d44535edcdf8a5408b0ffd3f27965f22d0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOTE4OjJBNkQxMDoyNDQzMkM4OjJGMTA5QkY6Njk2QjU1RkMiLCJ2aXNpdG9yX2lkIjoiNzkzNzY1NzAxMjg3Njk1NzE4MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 650c9feecdacc515cddda72ee2b3146456163feb0b713ee058315a3595b454af |
| hovercard-subject-tag | issue:3718943977 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/TheAlgorithms/JavaScript/1866/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b463baceca457c5e3c54228b4ec08cf735fb69ead5c79a74c74583ded29203c1/TheAlgorithms/JavaScript/issues/1866 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b463baceca457c5e3c54228b4ec08cf735fb69ead5c79a74c74583ded29203c1/TheAlgorithms/JavaScript/issues/1866 |
| og:image:alt | Motivation Numbers formed by repeating digits or repeating blocks—such as 111111, 424424, or structures like 10ⁿ + 1 (e.g., 100000001)—follow predictable patterns in number theory. These patterns a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ridge-kimani |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| turbo-cache-control | no-preview |
| go-import | github.com/TheAlgorithms/JavaScript git https://github.com/TheAlgorithms/JavaScript.git |
| octolytics-dimension-user_id | 20487725 |
| octolytics-dimension-user_login | TheAlgorithms |
| octolytics-dimension-repository_id | 97086543 |
| octolytics-dimension-repository_nwo | TheAlgorithms/JavaScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 97086543 |
| octolytics-dimension-repository_network_root_nwo | TheAlgorithms/JavaScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width