[Paper Review] Improved algorithms for left factorial residues
This paper presents optimized algorithms for computing left factorial residues !p mod p, leveraging matrix factorial representations and remainder trees to reduce time complexity to O(n log³⁺⁰ n) for all primes p ≤ n. The authors extend the search to p < 240, confirming no counterexamples to Kurepa’s conjecture or socialist primes in this range, with computations performed using advanced arithmetic libraries and high-performance hardware.
We present improved algorithms for computing the left factorial residues $!p=0!+1!+...+(p-1)! \!\mod p$. We use these algorithms for the calculation of the residues $!p\!\mod p$, for all primes $p$ up to $2^{40}$. Our results confirm that Kurepa's left factorial conjecture is still an open problem, as they show that there are no odd primes $p<2^{40}$ such that $p$ divides $!p$. Additionally, we confirm that there are no socialist primes $p$ with $5<p<2^{40}$.
Motivation & Objective
- To develop faster algorithms for computing left factorial residues !p mod p, where !p = 0! + 1! + ... + (p−1)!.
- To extend the search range for potential counterexamples to Kurepa’s conjecture beyond previous limits.
- To verify the absence of socialist primes p > 5 up to p < 240, based on the condition (!p−2)² ≡ 1 (mod p).
- To optimize computational efficiency using matrix factorial representations and remainder tree techniques.
- To provide high-precision verification of results using independent O(p⁰.⁵⁺⁰) algorithms.
Proposed method
- Representing n! and !n via matrix factorial Mn = C1C2⋯Cn = [[n!, !n], [0, 1]], where Ck = [[k, 1], [0, 1]].
- Applying [4, Theorem 8] to compute single residues rp = !p mod p in O(p⁰.⁵⁺⁰) time using Fast Fourier Transform-based polynomial multiplication.
- Using a product tree structure to compute residues for all primes in intervals (m, n] simultaneously, achieving O((n−m) log³⁺⁰ n) complexity.
- Implementing four-phase computation: (1) product tree for Pi,j, (2) Mm mod P0,0 using product trees, (3) Ai,j = ∏Ck mod Pi,j, and (4) Ri,j = Mm ⋅ ∏Ai,r mod Pi,j to extract rp.
- Leveraging GMP and NTT libraries for large integer arithmetic, with multithreading and SSD caching to minimize I/O bottlenecks.
- Verifying results using an independent O(p⁰.⁵⁺⁰) algorithm via NTL library for selected primes.
Experimental results
Research questions
- RQ1Are there any odd primes p < 240 such that p divides the left factorial !p, contradicting Kurepa’s conjecture?
- RQ2Do any socialist primes p > 5 exist in the range 5 < p < 240, where all factorials 2!, 3!, ..., (p−1)! mod p are distinct?
- RQ3Can the computational complexity of computing left factorial residues be reduced below O(n²/log n) for all p < n?
- RQ4How well do heuristic models predict the distribution of |rp| < ℓ for large ℓ in the interval (2³⁴, 2⁴⁰)?
- RQ5To what extent can memory-space trade-offs improve performance in large-scale residue computations?
Key findings
- No odd primes p < 240 satisfy p | !p, confirming Kurepa’s conjecture remains unrefuted within this range.
- There are no socialist primes p with 5 < p < 240, extending prior results up to p < 10¹¹.
- The heuristic prediction for the number of primes with |rp| < 10⁷ in (2³⁴, 2⁴⁰) is 3,250,379, closely matching the actual count of 3,250,456.
- For |rp| < 100, 24 primes were found in (2³⁴, 2⁴⁰), slightly below the expected 32, but consistent with heuristic estimates for larger ℓ.
- Phase 2, computing Mm mod P0,0, consumed ~65% of total 33,000 core hours, with up to 80% in later blocks, indicating it is the computational bottleneck.
- The implementation, available at https://github.com/milostatarevic/left-factorial, used 64GB RAM and 16TB disk space, with 6-core CPU and optimized I/O via SSD caching.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.