How many primes would a Giuga counterexample need?

4 of 7 main results in Lean (57%); 2 of 7 main results by Lean + certificate (>= 8,138 prime divisors and ≥ 40,748 digits via exact-integer depth-6 certificates plus conditional Lean lifting theorems) and 1 of 7 by certificate only (exact normal-set and local-class digit minima); Giuga's conjecture remains open · AI-generated and directed by Tyler B. Hughes · No human mathematician has yet refereed the proof.

Giuga guessed that a simple sum test picks out exactly the primes among the numbers from 2 up. Lean proves that any number that passes the test without being prime would need at least 578 different prime factors and more than 1,803 digits.

Every number n ≥ 2 that is not prime and for which 1ⁿ⁻¹ + 2ⁿ⁻¹ + … + (n − 1)ⁿ⁻¹ leaves remainder n − 1 on division by n has at least 578 different prime factors and is larger than 10¹⁸⁰³.

For a prime n each term of the sum 1ⁿ⁻¹ + 2ⁿ⁻¹ + … + (n − 1)ⁿ⁻¹ leaves remainder 1 on division by n, so the sum leaves remainder n − 1, and Giuga conjectured in 1950 that no other number n ≥ 2 does this. Borwein, Maitland and Skerritt showed in 2013 that a counterexample would need at least 4,771 prime factors and 19,908 digits. Lean proves smaller bounds with no outside input, and also checks the method that, together with an outside computer certificate, gives at least 8,138 prime factors and 40,748 digits.

Why a counterexample needs at least 9 primes

The test: for n = 7, each of 1⁶, 2⁶, …, 6⁶ leaves remainder 1 on division by 7, so the sum leaves remainder 6 = n − 1. For n = 9, which is not prime, the sum 1⁸ + 2⁸ + … + 8⁸ leaves remainder 6, not 8, so 9 fails the test, as Giuga expected.

A number that passed without being prime would be odd and a product of different primes, and the fractions 1/p over its primes p would add up to more than 1. Also no prime q of it could divide r − 1 for another prime r of it. So 3 and 7 cannot both be used (3 divides 6), and neither can 5 and 11 (5 divides 10).

Write each 1/p as 1/13 plus a bonus 1/p − 1/13. Only the primes below 13, which are 3, 5, 7 and 11, have a positive bonus, and from each forbidden pair at most the larger bonus counts: 1/3 − 1/13 = 10/39 and 1/5 − 1/13 = 8/65. Together that is 74/195.

So the sum of the 1/p is at most (number of primes)/13 + 74/195. For it to pass 1, the number of primes must exceed 13 · (1 − 74/195) = 121/15, which is about 8.07. So there are at least 9 primes.

Lean checks this calculation. The same idea, with the odd primes below 3,000 and 312 priced pairs (108 when 3 is used) checked by computer inside Lean, gives at least 575 primes and then at least 578.

From a power sum to a set of primes

A counterexample is a number n ≥ 2, not prime, whose power sum 1ⁿ⁻¹ + … + (n − 1)ⁿ⁻¹ leaves remainder n − 1 on division by n. Lean proves that for such n this holds exactly when every prime p dividing n has both p − 1 and p dividing n/p − 1. So a counterexample is odd, has no repeated prime factor, and its primes form a normal set (no q divides r − 1), with the sum of n/p over them equal to v·n + 1 for a whole number v ≥ 1, so the fractions 1/p add up to more than 1.

  • The prime factors of a counterexample form a normal set of odd primes

    If n is a counterexample, its prime factors are odd, and no prime factor q divides r − 1 for another prime factor r.

  • n is a counterexample to Giuga's conjecture
  • P is a normal set of odd primes
  • n is a counterexample to Giuga's conjecture
  • n meets the Carmichael condition
  • n meets the Giuga condition
  • P is a normal set of odd primes
  • A number n ≥ 2 that is not prime is a counterexample exactly when it meets both conditions

    For n ≥ 2 not prime: n is a counterexample exactly when, for every prime p dividing n, both p − 1 and p divide n/p − 1.

  • A counterexample has a value v

    If n is a counterexample, there is exactly one whole number v ≥ 1 with the sum of n/p over the prime factors p of n equal to v·n + 1.

  • The reciprocals of the prime factors of a counterexample add up to more than 1

    If n is a counterexample, the sum of 1/p over its prime factors p is more than 1.

  • The power sum modulo a prime

    For a prime p and e ≥ 1, 1ᵉ + 2ᵉ + … + (p − 1)ᵉ is −1 modulo p when p − 1 divides e, and 0 modulo p otherwise.

  • The sum modulo a prime factor

    If n ≥ 2 and the prime p divides n, then 1ⁿ⁻¹ + … + (n − 1)ⁿ⁻¹ is −(n/p) modulo p when p − 1 divides n − 1, and 0 modulo p otherwise.

Rules a counterexample must obey

Write v for the whole number with ∑ n/p = v·n + 1. Lean proves that the number of prime factors is v + 1 modulo 8, that the prime factors add up to v + n modulo 8, and that the number of prime factors leaving remainder 3 on division by 4 is 0 or 1 modulo 4. When v = 1, leaving out any one prime factor brings the sum of the other reciprocals below 1.

  • The number of prime factors of a counterexample of value v is v + 1 modulo 8

    If n is a counterexample and the sum of n/p over its prime factors is v·n + 1, then the number of prime factors leaves the same remainder on division by 8 as v + 1.

    theorem GiugaChallenge.giuga_card_mod_eight {n : ℕ} {v : ℕ} (hn : IsGiugaCounterexample n) (hv : ∑ p ∈ n.primeFactors, n / p = v * n + 1) :
      n.primeFactors.card ≡ v + 1 [MOD 8]
  • The prime factors of a counterexample of value v add up to v + n modulo 8

    If n is a counterexample and the sum of n/p over its prime factors p is v·n + 1, then the prime factors add up to a number that leaves the same remainder on division by 8 as v + n.

    theorem GiugaChallenge.giuga_residue_mod_8 {n : ℕ} {v : ℕ} (hn : IsGiugaCounterexample n) (hv : ∑ p ∈ n.primeFactors, n / p = v * n + 1) :
      ∑ p ∈ n.primeFactors, p ≡ v + n [MOD 8]
  • The number of prime factors leaving remainder 3 on division by 4 is 0 or 1 modulo 4

    If n is a counterexample, the number of its prime factors that leave remainder 3 on division by 4 itself leaves remainder 0 or 1 on division by 4.

    theorem GiugaChallenge.giuga_reciprocity_rule {n : ℕ} (hn : IsGiugaCounterexample n) :
      {p ∈ n.primeFactors | p % 4 = 3}.card % 4 = 0 ∨ {p ∈ n.primeFactors | p % 4 = 3}.card % 4 = 1
  • For a counterexample of value 1, the reciprocals of its prime factors add up to less than 1 + 1/p for each prime factor p

    If n is a counterexample with the sum of n/p over its prime factors equal to n + 1, and p is a prime factor of n, then the sum of 1/q over all prime factors q is less than 1 + 1/p. So leaving out p brings the sum below 1.

    theorem GiugaChallenge.giuga_exactness_rule {n : ℕ} (hn : IsGiugaCounterexample n) (hv1 : ∑ p ∈ n.primeFactors, n / p = n + 1) {p : ℕ} (hp : p ∈ n.primeFactors) :
      ∑ q ∈ n.primeFactors, 1 / ↑q - 1 < 1 / ↑p
  • For odd n with no repeated prime factor and of value v, the number of prime factors is v + 1 modulo 4

    If n is odd, no prime divides it twice, and the sum of n/p over its prime factors p is v·n + 1, then the number of prime factors leaves the same remainder on division by 4 as v + 1.

  • The sum minus the product of a set of odd numbers, modulo 8

    For a set Q of odd numbers with k₃ members that leave remainder 3 on division by 4, the sum of Q minus the product of Q equals |Q| − 1 − 4·k₃(k₃ − 1)/2 modulo 8.

Prices on forbidden pairs

Fix the primes of a normal set below a cut and call the rest its tail. Each tail prime x gets a weight, such as 1/x − 1/Λ, and each forbidden pair q < r with q dividing r − 1 gets a price of at least 0. Because a normal tail never holds both primes of a pair, its total weight is at most the sum of the prices plus, for each prime, the weight its prices leave uncovered. Lean turns this into lower bounds on the number of tail primes and on the sum of their logarithms, and combines them over every prefix.

  • Prices bound the number of tail primes

    Let T be a normal set of tail primes for the prefix S at a cut, whose reciprocals add up to more than the need of S. Take Λ > 0, a set U holding every tail prime below Λ, forbidden pairs E inside U, and prices η ≥ 0 on them. Then T has more than Λ·(N − B) members, where N is the need of S, B is the price bound of U, E, w and η, and w(x) = 1/x − 1/Λ.

  • Prices bound the size of the tail

    Under the same conditions, but with Λ ≥ 1 and 0 < μ ≤ Λ·ln Λ, the sum of ln x over T is more than μ·N − B, where N is the need of S, B is the price bound of U, E, w and η, and now w(x) = μ/x − ln x.

  • Count bounds over a full list of prefixes give a count bound for every normal set whose reciprocals add up to more than 1

    Let F contain every normal set of odd primes below a cut. Suppose each S in F carries a number Λ(S) > 0, a set U(S), forbidden pairs E(S) and prices η(S) ≥ 0 as in the count bound from prices, with B(S) − 1 at most Λ(S) times the difference between the need of S and its price bound. Then every normal set of odd primes whose reciprocals add up to more than 1 has at least as many members as the smallest value of |S| + B(S) over F.

  • Prices and a known count bound the size of the tail

    Let T be a normal set of tail primes for S at a cut whose reciprocals add up to more than the need of S, and with at least K members. Take μ > 0, ν ≥ 0 and C > 0 with μ/C + ν − ln C ≤ 0, a set U holding every tail prime below C, forbidden pairs E inside U and prices η ≥ 0. Then μ·N + ν·K − B is less than the sum of ln x over T, where N is the need of S, B is the price bound of U, E, w and η, and w(x) = μ/x + ν − ln x.

  • The refined size form with the count lifted to fit modulo 4

    Let P be a normal set of odd primes whose reciprocals add up to more than 1 and whose size leaves remainder 2 on division by 4. Let S be its members below a cut and K at most the number of the others. With μ ≥ 0 and the other choices as in the refined size form, the logarithm of the product of P is at least (the sum of ln s over S) + μ·N + ν·K' − B, where N is the need of S, B is the price bound of U, E, w and η, and K' is the lift of K for |S|.

  • The need of a set S
  • q and r form a forbidden pair
  • x is a tail prime for the prefix S at a cut
  • The price bound of U, E, w and η
  • The lift of K
  • Every normal set of odd primes whose reciprocals add up to more than 1 has at least 9 members

    The count bound from prices, with an empty prefix, Λ = 13, U = {3, 5, 7, 11}, the pairs (3, 7) and (5, 11), and prices 6/91 and 2/143 gives a price bound of 74/195, so such a set has more than 13·(1 − 74/195) = 121/15 members.

  • The need of a set S
  • q and r form a forbidden pair
  • x is a tail prime for the prefix S at a cut
  • A contains no pair from E
  • The price bound of U, E, w and η
  • A normal set contains no forbidden pair

    If T is a normal set of odd primes and every pair in E is a forbidden pair, then T contains no pair from E.

  • A pair-free subset of U weighs at most the price bound

    If A ⊆ U contains no pair from E and every price is at least 0, the sum of w over A is at most the price bound of U, E, w and η.

  • The weight of a normal set inside U is at most the price bound

    If every pair in E is a forbidden pair of members of U, every price is at least 0 and T is a normal set of odd primes, then the sum of w over the members of T in U is at most the price bound of U, E, w and η.

At least 578 primes and more than 1,803 digits, with no outside input

Splitting at 5, a normal set either contains 3 or not, and for each case Lean runs a price check with cut 3,000 (312 priced pairs without 3, 108 with 3), which gives at least 575 members. If v ≥ 2 the reciprocals add up to more than 2, and the bound for sums above 2, with fewer than 575 odd primes below 4,211, gives at least 4,786; if v = 1 the count is 2 modulo 8, so at least 578. Then n is at least the product of the 574 odd primes below 4,211 times 4,211⁴, which Lean computes to exceed 10¹⁸⁰³.

  • Every counterexample has at least 578 different prime factors

    If n is a counterexample to Giuga's conjecture, then n has at least 578 different prime factors.

    theorem GiugaChallenge.giuga_unconditional_578_primes {n : ℕ} (hn : IsGiugaCounterexample n) :
      578 ≤ n.primeFactors.card
  • Every counterexample is larger than 10¹⁸⁰³

    If n is a counterexample to Giuga's conjecture, then n > 10¹⁸⁰³, so n has at least 1,804 digits.

  • Every normal set of odd primes whose reciprocals add up to more than 1 has at least 575 members

    If P is a normal set of odd primes and the sum of 1/p over P is more than 1, then P has at least 575 members.

  • A count bound for sums above 1 gives one for sums above 2

    Suppose every normal set of odd primes whose reciprocals add up to more than 1 has at least N₁ members, and fewer than N₁ odd primes lie below q. Then every normal set of odd primes whose reciprocals add up to more than 2 has at least N₁ + q members.

  • A passed price check with target K gives K + 1 tail primes

    Let T be a normal set of tail primes for S at the cut 5 whose reciprocals add up to more than the need of S, with that need at least L/10⁶, and with 3 in S when the check leaves out each p with 3 dividing p − 1. If the price check with need L millionths and target K passes, T has at least K + 1 members.

  • The price check passes for the empty prefix with target 574

    Lean computes the check for the 312 pairs, with need 1 and target 574, and gets true.

  • The price check passes for the prefix {3} with target 586

    Lean computes the check for the 108 pairs, with need at least 0.666666 and target 586, and gets true.

  • The unpacked prices on a normal set add up to at most the total price

    For a normal set A of odd primes below 3,000, the tree is well formed, and if every check passed, the prices on members of A add up to at most the total of all prices. A normal set holds at most one number of each pair.

  • There are fewer than 575 odd primes below 4,211

    The number of odd primes below 4,211 is at most 574.

  • The sieve leaves 574 numbers below 4,211

    Lean computes that the bit count of the survivors in the low 2,105 places is 574.

  • The product of the survivors below 4,211, times 4,211⁴, exceeds 10¹⁸⁰³

    Lean computes that 10¹⁸⁰³ is less than the product of the odd numbers below 4,211 that the sieve leaves, times 4,211⁴.

  • A lower bound on a product from its small members and its count

    Suppose every member of P below M is in Q, every member of Q is at most M, with M ≥ 1, Q has at most K members, and P has at least K + r members. Then (the product of Q) times M to the power r is at most the product of P.

  • Every odd prime below 83,341 survives the sieve

    If p is an odd prime below 83,341, digit (p − 1)/2 of the mask of survivors is 1.

  • The number of 1 digits below place 65,536 is at most the 16-step bit count

    The number of places i below 65,536 at which x has binary digit 1 is at most the bit count of x after 16 steps.

Two sets of 8,135 and 8,138 primes

Lean builds a normal set G of 8,135 odd primes from 5 to 321,053 whose reciprocals add up to more than 1 and whose product has 40,733 digits. Swapping 97,387 for 321,073, 321,109, 321,143 and 1,999,993 gives a set W of 8,138 primes that obeys the local rules, with the deletion rule in the form "at most 1", and whose product has 40,751 digits. One computation inside Lean checks both sets.

  • There is a set of 8,138 odd primes that obeys seven local rules

    There is a normal set W of 8,138 odd primes, without 3, whose reciprocals add up to more than 1, such that leaving out any one member brings that sum to at most 1, the number of members leaving remainder 3 on division by 4 is 0 or 1 modulo 4, the sum of the members leaves the same remainder on division by 8 as 1 plus their product, and the product lies between 10⁴⁰⁷⁵⁰ and 10⁴⁰⁷⁵¹.

  • There is a normal set of 8,135 odd primes whose reciprocals add up to more than 1

    There is a normal set G of 8,135 odd primes such that the sum of 1/p over G is more than 1, both as an exact fraction and as a real number, and the product of its members lies between 10⁴⁰⁷³² and 10⁴⁰⁷³³, so it has 40,733 digits.

  • The facts about W

    W is a normal set of 8,138 odd primes from 5 to 1,999,993, the sum of 1/p over W is more than 1, leaving out any one member brings it to at most 1, exactly 4,032 members leave remainder 3 on division by 4, the sum of W leaves the same remainder on division by 8 as 1 plus its product, and the product lies between 10⁴⁰⁷⁵⁰ and 10⁴⁰⁷⁵¹.

  • The facts about G

    G is a normal set of 8,135 odd primes from 5 to 321,053, the sum of 1/p over G is more than 1, and its product lies between 10⁴⁰⁷³² and 10⁴⁰⁷³³.

  • The bundle check passes

    Lean computes the bundle check on the packed primes with the powers 10⁴⁰⁷³², 10⁴⁰⁷³³, 10⁴⁰⁷⁵⁰ and 10⁴⁰⁷⁵¹ and gets true.

  • What a passed bundle check proves about G and W

    If 2ᵈ ≥ 8,135, the sieve mask leaves only primes and the bundle check passes, then G and W have every property listed for them in the facts about G and the facts about W, with the given powers of 10 as product bounds.

  • The computed summary describes the packed set

    For c packed numbers, if 1 ≤ c ≤ 2ᵈ and the list is increasing, the packed set has c members, all odd and between 3 and 321,053, each marked in the summary's mask with its multiples marked in the multiples mask; every number marked in the mask is a member; and the product, the count of members leaving remainder 3 on division by 4 and the bounds on the sum of 1/p are as the summary says.

  • A number the sieve leaves up to 321,143 is prime

    For 2 ≤ k ≤ 160,571, if digit k of the crossed-out mask to 321,143 is 0, then 2k + 1 is prime.

What follows from the 8,135 bound

These theorems take as a hypothesis that every normal set of odd primes whose reciprocals add up to more than 1 has at least 8,135 members, which an outside certificate supplies. Lean proves there are at most 8,134 odd primes below 83,341, so the bound for sums above 2 gives at least 91,476 members when the reciprocals add up to more than 2. Then every counterexample has at least 8,138 prime factors and exceeds 10³⁶⁰⁸³, and with the per-prefix certificates as further hypotheses it exceeds 10⁴⁰⁷⁴⁷.

  • Given the 8,135 bound, every counterexample has at least 8,138 prime factors

    Assume every normal set of odd primes whose reciprocals add up to more than 1 has at least 8,135 members. Then every counterexample to Giuga's conjecture has at least 8,138 different prime factors.

  • Given the 8,135 bound and the per-prefix certificates, every counterexample is larger than 10⁴⁰⁷⁴⁷

    Assume the 8,135 bound. Let F contain every normal set of odd primes below 17. Suppose that for each S in F a count K(S) of primes from 17 up is guaranteed in every normal set with prefix S whose reciprocals add up to more than 1, and that numbers μ, ν, C, a set U, pairs E and prices η are given that satisfy the refined size form's conditions with the lifted bound above 40,747·ln 10. Then every counterexample n satisfies n > 10⁴⁰⁷⁴⁷, so it has at least 40,748 digits.

  • Given the 8,135 bound, every counterexample is larger than 10³⁶⁰⁸³

    Under the same hypothesis, every counterexample n satisfies n > 10³⁶⁰⁸³, so it has at least 36,084 digits.

  • Given the 8,135 bound, a normal set whose reciprocals add up to more than 2 has at least 91,476 members

    Assume every normal set of odd primes whose reciprocals add up to more than 1 has at least 8,135 members. Then every normal set of odd primes whose reciprocals add up to more than 2 has at least 91,476 members.

  • Given the 8,135 bound, a normal set whose reciprocals add up to more than 2 has a product above 10⁴⁴⁶¹⁷⁷

    Under the same hypothesis, every normal set of odd primes whose reciprocals add up to more than 2 has a product larger than 10⁴⁴⁶¹⁷⁷.

  • Any 8,135 odd primes include one that is at least 83,341

    If Q is a set of odd primes with at least 8,135 members, some member of Q is at least 83,341.

  • There are fewer than 8,135 odd primes below 83,341

    Every odd prime below 83,341 survives the sieve, and the sieve's bit count, which is at least the number it leaves, is 8,134, so there are at most 8,134 odd primes below 83,341.

  • The sieve's bit count below 83,341 is 8,134

    Lean computes the bit count of the mask of survivors after 16 steps and gets 8,134.

    theorem Giuga.swarPopcountUp_survivorMask :
      swarPopcountUp 16 survivorMask = 8134