Giuga's criterion for the congruence
ProvedFCP.AgohGiuga.giuga_criterionGiuga's criterion. Let be an integer. Then the Giuga congruence
holds if and only if for every prime dividing one has
The first family of conditions says that is a Giuga number (in the usual sense, extended here to prime , for which and the conditions are vacuous); the second family is Korselt's criterion in its form, and together with the first it says that is a Carmichael number. The criterion is the arithmetic heart of the Agoh--Giuga conjecture: it converts the congruence, a statement about a sum of large powers, into finitely many divisibility conditions on the prime factorisation of , and it is the reason a counterexample to the conjecture is known to be simultaneously a Carmichael number and a Giuga number.
Note that the first condition forces to be squarefree: if then , which is incompatible with .
Formalization Note The sum is taken over the integers with , and all arithmetic is in the natural numbers, so the congruence is written in the equivalent divisibility form . The subtractions and are truncated natural subtraction, which is harmless because and for every prime divisor of .
import Mathlib
namespace FCP.AgohGiuga
theorem giuga_criterion (n : ℕ) (hn : 2 ≤ n) :
n ∣ 1 + ∑ i ∈ Finset.Ioo 0 n, i ^ (n - 1) ↔
∀ p : ℕ, p.Prime → p ∣ n → p ∣ n / p - 1 ∧ (p - 1) ∣ n / p - 1 := by sorry
end FCP.AgohGiuga