# Fermat quotient

In number theory, the Fermat quotient of an integer a with respect to an odd prime p is defined as
    $q_{p}(a)={\frac {a^{p-1}-1}{p}},$
or
    $\delta _{p}(a)={\frac {a-a^{p}}{p}}$.
This article is about the former; for the latter see p-derivation. The quotient is named after Pierre de Fermat.
If the base a is coprime to the exponent p then Fermat's little theorem says that q$_p$(a) will be an integer. If the base a is also a generator of the multiplicative group of integers modulo p, then q$_p$(a) will be a cyclic number, and p will be a full reptend prime.

## Properties

From the definition, it is obvious that
    ${\begin{aligned}q_{p}(1)&\equiv 0&&{\pmod {p}}\\q_{p}(-a)&\equiv q_{p}(a)&&{\pmod {p}}\quad ({\text{since }}2\mid p-1)\end{aligned}}$
In 1850, Gotthold Eisenstein proved that if a and b are both coprime to p, then:
    ${\begin{aligned}q_{p}(ab)&\equiv q_{p}(a)+q_{p}(b)&&{\pmod {p}}\\q_{p}(a^{r})&\equiv rq_{p}(a)&&{\pmod {p}}\\q_{p}(p\mp a)&\equiv q_{p}(a)\pm {\tfrac {1}{a}}&&{\pmod {p}}\\q_{p}(p\mp 1)&\equiv \pm 1&&{\pmod {p}}\end{aligned}}$
Eisenstein likened the first two of these congruences to properties of logarithms. These properties imply
    ${\begin{aligned}q_{p}\!\left({\tfrac {1}{a}}\right)&\equiv -q_{p}(a)&&{\pmod {p}}\\q_{p}\!\left({\tfrac {a}{b}}\right)&\equiv q_{p}(a)-q_{p}(b)&&{\pmod {p}}\end{aligned}}$
In 1895, Dmitry Mirimanoff pointed out that an iteration of Eisenstein's rules gives the corollary:
    $q_{p}(a+np)\equiv q_{p}(a)-n\cdot {\tfrac {1}{a}}{\pmod {p}}.$
From this, it follows that:
    $q_{p}(a+np^{2})\equiv q_{p}(a){\pmod {p}}.$

## Lerch's formula

M. Lerch proved in 1905 that
    $\sum _{j=1}^{p-1}q_{p}(j)\equiv W_{p}{\pmod {p}}.$
Here $W_{p}$ is the Wilson quotient.

## Special values

Eisenstein discovered that the Fermat quotient with base 2 could be expressed in terms of the sum of the reciprocals modulo p of the numbers lying in the first half of the range {1, ..., p − 1}:
    $-2q_{p}(2)\equiv \sum _{k=1}^{\frac {p-1}{2}}{\frac {1}{k}}{\pmod {p}}.$
Later writers showed that the number of terms required in such a representation could be reduced from 1/2 to 1/4, 1/5, or even 1/6:
    $-3q_{p}(2)\equiv \sum _{k=1}^{\lfloor {\frac {p}{4}}\rfloor }{\frac {1}{k}}{\pmod {p}}.$
    $4q_{p}(2)\equiv \sum _{k=\lfloor {\frac {p}{10}}\rfloor +1}^{\lfloor {\frac {2p}{10}}\rfloor }{\frac {1}{k}}+\sum _{k=\lfloor {\frac {3p}{10}}\rfloor +1}^{\lfloor {\frac {4p}{10}}\rfloor }{\frac {1}{k}}{\pmod {p}}.$
    $2q_{p}(2)\equiv \sum _{k=\lfloor {\frac {p}{6}}\rfloor +1}^{\lfloor {\frac {p}{3}}\rfloor }{\frac {1}{k}}{\pmod {p}}.$
Eisenstein's series also has an increasingly complex connection to the Fermat quotients with other bases, the first few examples being:
    $-3q_{p}(3)\equiv 2\sum _{k=1}^{\lfloor {\frac {p}{3}}\rfloor }{\frac {1}{k}}{\pmod {p}}.$
    $-5q_{p}(5)\equiv 4\sum _{k=1}^{\lfloor {\frac {p}{5}}\rfloor }{\frac {1}{k}}+2\sum _{k=\lfloor {\frac {p}{5}}\rfloor +1}^{\lfloor {\frac {2p}{5}}\rfloor }{\frac {1}{k}}{\pmod {p}}.$

## Generalized Wieferich primes

If q$_p$(a) ≡ 0 (mod p) then a$^{p−1}$ ≡ 1 (mod p$^2$). Primes for which this is true for a = 2 are called Wieferich primes. In general they are called Wieferich primes base a. Known solutions of q$_p$(a) ≡ 0 (mod p) for small values of a are:
    a p (checked up to 5 × 10$^{13}$) OEIS sequence 12, 3, 5, 7, 11, 13, 17, 19, 23, 29, ... (All primes) A000040 21093, 3511 A001220 311, 1006003 A014127 41093, 3511 52, 20771, 40487, 53471161, 1645333507, 6692367337, 188748146801 A123692 666161, 534851, 3152573 A212583 75, 491531 A123693 83, 1093, 3511 92, 11, 1006003 103, 487, 56598313 A045616 1171 122693, 123653 A111027 132, 863, 1747591 A128667 1429, 353, 7596952219 A234810 1529131, 119327070011 A242741 161093, 3511 172, 3, 46021, 48947, 478225523351 A128668 185, 7, 37, 331, 33923, 1284043 A244260 193, 7, 13, 43, 137, 63061489 A090968 20281, 46457, 9377747, 122959073 A242982 212 2213, 673, 1595813, 492366587, 9809862296159 A298951 2313, 2481757, 13703077, 15546404183, 2549536629329 A128669 245, 25633 252, 20771, 40487, 53471161, 1645333507, 6692367337, 188748146801 263, 5, 71, 486999673, 6695256707 2711, 1006003 283, 19, 23 292 307, 160541, 94727075783
For more information, see and.
The smallest solutions of q$_p$(a) ≡ 0 (mod p) with a = n are:
    2, 1093, 11, 1093, 2, 66161, 5, 3, 2, 3, 71, 2693, 2, 29, 29131, 1093, 2, 5, 3, 281, 2, 13, 13, 5, 2, 3, 11, 3, 2, 7, 7, 5, 2, 46145917691, 3, 66161, 2, 17, 8039, 11, 2, 23, 5, 3, 2, 3, ... (sequence A039951 in the OEIS)
A pair (p, r) of prime numbers such that q$_p$(r) ≡ 0 (mod p) and q$_r$(p) ≡ 0 (mod r) is called a Wieferich pair.