Hostname: page-component-797576ffbb-k7d4m Total loading time: 0 Render date: 2023-12-02T12:32:24.774Z Has data issue: false Feature Flags: { "corePageComponentGetUserInfoFromSharedSession": true, "coreDisableEcommerce": false, "useRatesEcommerce": true } hasContentIssue false

On theorems of Fermat, Wilson, and Gegenbauer

Published online by Cambridge University Press:  12 September 2023

Heng Huat Chan
Department of Mathematics, National University of Singapore, Block S17, 10 Lower Kent Ridge Road, Singapore 119076, Singapore e-mail:
Song Heng Chan*
Division of Mathematical Sciences, School of Physical and Mathematical Sciences, Nanyang Technological University, 21 Nanyang Link, Singapore 637371, Singapore
Teoh Guan Chua
Department of Mathematics, Ngee Ann Secondary School, 1 Tampines Street 32, Singapore 529283, Singapore e-mail:
Cheng Yeaw Ku
Division of Mathematical Sciences, School of Physical and Mathematical Sciences, Nanyang Technological University, 21 Nanyang Link, Singapore 637371, Singapore e-mail:
Rights & Permissions [Opens in a new window]


In this article, we give generalizations of the well-known Fermat’s Little Theorem, Wilson’s theorem, and the little-known Gegenbauer’s theorem.

Creative Commons
Creative Common License - CCCreative Common License - BY
This is an Open Access article, distributed under the terms of the Creative Commons Attribution licence (, which permits unrestricted re-use, distribution, and reproduction in any medium, provided the original work is properly cited.
© The Author(s), 2023. Published by Cambridge University Press on behalf of The Canadian Mathematical Society

1 Introduction

The well-known Fermat’s Little Theorem states that for any prime p and any integer a,

(1.1) $$ \begin{align} a^p\equiv a\quad \pmod{p}. \end{align} $$

Wilson’s theorem, on the other hand, states that for any prime p,

(1.2) $$ \begin{align} (p-1)!\equiv -1\quad \pmod{p}. \end{align} $$

Around 1956, Moser [Reference Moser13] discovered the congruence

(1.3) $$ \begin{align} (p-1)!a^p+(p-1)^2 a\equiv 0\quad \pmod{p}. \end{align} $$

By setting $a=1$ in (1.3), one obtained (1.2), and using (1.2) in (1.3), we deduced (1.1). On the other hand, (1.3) follows immediately from (1.2) and (1.1). Moser’s congruence (1.3) was mentioned in the book of Sierpinski [Reference Sierpinski20, pp. 216 – 217]. Sierpinski appeared to have mistaken that Moser discovered

(1.4) $$ \begin{align} (p-1)!a+a^p\equiv 0\quad \pmod{p} \end{align} $$

when it should have been (1.3).

About 30 years later, Moser’s brother, William Moser [Reference Moser14], found a generalization of Moser’s congruence (1.3) given by

(1.5) $$ \begin{align} \sum_{d|n} \varphi^2(d) \left(\dfrac{n}{d}\right)! d^{n/d} a^{n/d}\equiv 0\quad \pmod{n^2}, \end{align} $$


$$ \begin{align*} \varphi(n)=\sum_{\substack{1\leq k\leq n \\ \text{gcd}(k,n)=1}}^n 1. \end{align*} $$

When n is a prime p, (1.5) reduces to (1.3). Since the special case of (1.5) is discovered by L. Moser and (1.5) is discovered by his brother, we will name (1.5) the Moser–Moser congruence. The Moser–Moser congruence is a generalization of (1.3), while (1.4) is its analog. In this article, we will derive new generalizations of (1.3) and (1.4).

In 2006, a special case of (1.5) with the value $a=1$ , namely,

(1.6) $$ \begin{align} \sum_{d|n} \varphi^2(d) \left(\dfrac{n}{d}\right)! d^{n/d} \equiv 0\quad \pmod{n^2}, \end{align} $$

was rediscovered by Evans [Reference Evans9] as a generalization of (1.2). It turns out that Evans’ proof of (1.6), which is different from Moser’s proof, can be modified to derive (1.5).

The proofs of Evans and Moser of (1.5) are different. Evans used the action of the group ${\mathbf Z}/n{\mathbf Z}$ on the set of Hamilton cycles with n vertices, whereas Moser used the action of the group ${\mathbf Z}/n{\mathbf Z}\times {\mathbf Z}/n{\mathbf Z}$ on the set of line permutations of $\{1,2,\ldots , n\}$ . In this article, we will present a third proof of (1.6). We will then deduce the Moser–Moser congruence (1.5), which is (1.6) with an extra factor of $a^{n/d}$ , from L. Gegenbauer’s theorem [Reference Gegenbauer10] is given as follows.

Theorem 1.1 Let n and a be positive integers. Let $F:{\mathbf Z}^+\rightarrow {\mathbf Z}.$ Suppose $F(n)\neq \mu (n),$ where $\mu $ is defined in Section 4 (see Definition 4.1). If

$$ \begin{align*} \sum_{d|n} F(d)\equiv 0\quad \pmod{n}, \end{align*} $$


$$ \begin{align*}\sum_{d|n} F(d) a^{n/d}\equiv 0\quad \pmod{n}.\end{align*} $$


(1.7) $$ \begin{align}\sum_{d|n}\mu(d)a^{n/d}\equiv 0 \quad \pmod{n} \end{align} $$

is true, it does not follow from Theorem 1.1 and the fact [Reference Apostol3, Theorem 2.1] that

$$ \begin{align*} \sum_{d|n}\mu(d)=0\,, \end{align*} $$

for $n>1$ . This is because (1.7) is used in the proof of Theorem 1.1 and (1.7) needs to be proved separately as what Gegenbauer did in his article.

In the next section, we state the Frobenius–Burnside theorem, a fundamental tool used in proving many congruences such as (1.5) and (1.7). In Section 3, we give a new proof of the Moser–Moser congruence (1.5) using the Frobenius–Burnside. In Section 4, we give a new proof of an interesting result of András [Reference András1, p. 267, Remark 2] (see Theorem 4.3) and give a brief history of (1.7) and its analogue. In Section 5, we give a generalization of (1.5). In the final section, we prove a generalization of Theorem 1.1.

In this article, several congruences such as (1.5) are stated modulo $n^2$ , whereas Theorems such as Theorem 1.1 hold modulo n. We emphasize that in all our examples, we derive

$$ \begin{align*} \dfrac{1}{n}\sum_{d|n} F(d)\equiv 0\quad \pmod{n} \end{align*} $$

using theorems such as Theorem 1.1 and conclude that

$$ \begin{align*} \sum_{d|n} F(d)\equiv 0\quad \pmod{n^2}. \end{align*} $$

We now summarize our contributions. In this article, we present a new proof of the Moser–Moser congruence with the help of Theorem 1.1. Surprisingly, this theorem has remained relatively obscure despite its significance. We have also found the origin of (1.6). We have identified an error in Sierpinski’s book, where he mistakenly attributed (1.4) instead of (1.3) to L. Moser. Additionally, we have unveiled a comprehensive generalization that encompasses both (1.3) and (1.4) (see Section 5). By using Theorem 4.3 and Theorem 6.1, we derived many new congruences from well-established ones, such as Moreau’s congruence.

We would like to thank the anonymous referee for his/her invaluable insights and the references [Reference Byszewski, Graff and Ward4, Reference Wójcik23]. These references establish crucial connections between our work and Dold sequences. Notably, one can see a link between our generalization of the Gegenbauer theorem (Theorem 6.1) and [Reference Wójcik23, Theorem 7]. This connection becomes apparent when we recognize that the function $G(n)$ defined in Theorem 6.1 is Dold sequences, leading to the conclusion that Theorem 8 follows from the equivalence of the statements in [Reference Wójcik23, Theorem 7]. This connection also shows that many of the examples discussed in this article are, therefore, examples of Dold sequences. Some of the sequences contained in (6.4) and in (6.6) might pose challenges for direct verification as Dold sequences under alternative circumstances. Finally, as highlighted by the referee, several previous works, including [Reference András1, Reference Wójcik23], have overlooked the significance of the Gegenbauer theorem (Theorem 1.1). Our article serves to rectify this gap in the mathematical discourse.

2 The Frobenius–Burnside theorem

Let $(G,\circ )$ be a group with identity $1_G$ , and let X be a nonempty set. A left action of the group G on X is a function

$$ \begin{align*} \bullet : G\times X \rightarrow X, \end{align*} $$

which we write $g\bullet x$ instead of $\bullet (g,x)$ , with the following properties that for all $a,b\in G$ and $x\in X$ :

  1. (1) $a\bullet (b\bullet x) = (a\circ b)\bullet x,$

  2. (2) $1_G\bullet x = x.$

We say that G acts on X via $\bullet $ .

Given a group G acting (via $\bullet $ ) on a nonempty set X, we define a relation $\sim $ as follows:

$$ \begin{align*}u \sim x \text{ if and only if there exists a } g\in G \text{ such that } g\bullet x=u. \end{align*} $$

The relation $\sim $ is an equivalence relation on X. This implies that X is a disjoint union of equivalence classes $\mathcal O_x$ , which are also called G-orbits, where

$$ \begin{align*} {\mathcal O}_x:=\{u\in X|u\sim x\}. \end{align*} $$

When X is a finite set, the number of distinct G-orbits in X is given by the following theorem.

Theorem 2.1 (The Frobenius–Burnside theorem)

Let G be a group acting on a finite set X, and let

$$ \begin{align*} \mathrm{Fix}(g)=\{x\in X| g\bullet x=x\}. \end{align*} $$

The number of disjoint G-orbits N in X is given by

$$ \begin{align*} N=\dfrac{1}{|G|}\sum_{g\in G} |\text{Fix}(g)|, \end{align*} $$

where $|S|$ denotes the number of elements in the set S.

We emphasize that in the proof of Theorem 2.1, one has to show that if

$$ \begin{align*}\text{Stab}_G(x)=\{g\in G|g\bullet x=x\},\end{align*} $$


$$ \begin{align*}|\mathcal O_x|=\dfrac{|G|}{|\text{Stab}_G(x)|}.\end{align*} $$

This shows immediately that

(2.1) $$ \begin{align} |{\mathcal O}_x | \text{ divides } |G|. \end{align} $$

For a complete proof of the Frobenius–Burnside theorem, see [Reference Robinson17, Chapter 5].

3 A new proof of the Moser–Moser congruence

For any positive integer n, let $S_n$ denote the set of bijections on

$$ \begin{align*}\{1,2,\ldots, n-1,n\}.\end{align*} $$

For $g \in S_n$ , let

$$ \begin{align*} g=\tau_1 \tau_2 \cdots \tau_r \end{align*} $$

be the complete factorization (which is unique up to the arrangement of the cycles) of g into disjoint cycles. If $\tau _j$ is a cycle with length $\lambda _j$ , then we say that g has cycle type

$$ \begin{align*} (\lambda_1,\lambda_2,\ldots, \lambda_r). \end{align*} $$

If g has $a_j$ cycles of length j, we say that g has cycle structure

$$ \begin{align*} \langle\displaystyle 1^{a_1}2^{a_2}\cdots n^{a_n}\rangle. \end{align*} $$

For example, if

$$ \begin{align*} g =(1\, 2)(3\, 4)(5\, 6)(7\, 8\, 9), \end{align*} $$

then the cycle type and cycle structure of g are $(3, 2, 2, 2)$ and $\langle 1^0 2^{3}3^{1}\rangle $ , respectively.

The following lemma is well known [Reference Cameron5, p. 244].

Lemma 3.1 Let $g\in S_n$ with cycle structure $\langle 1^{a_1}2^{a_2} \cdots n^{a_n}\rangle $ , and let

$$ \begin{align*} \mathcal{C}(g) = \{x \in S_n| g^{-1}xg = x\} \end{align*} $$

be the centralizer of g in $S_n$ . Then

$$ \begin{align*} |\mathcal{C}(g)| = (1^{a_1}2^{a_2} \cdots n^{a_n}) a_1!a_2! \cdots a_n!=\prod_{j=1}^n j^{a_j} a_j!.\end{align*} $$

We will use Lemma 3.1 to derive the following lemma.

Lemma 3.2 Suppose $g, h\in S_n$ . Let $F(g,h) = \{x \in S_n|g^{-1}xh = x\}$ . Then $F(g,h) $ is nonempty if and only if g and h have the same cycle type, or equivalently, g and h are conjugate to each other in $S_n$ . Moreover, if $F(g,h)$ is nonempty, then

$$\begin{align*}|F(g,h)| = \prod_{j=1}^n j^{a_j}a_j!,\end{align*}$$

where $\langle 1^{a_1}2^{a_2} \cdots n^{a_n}\rangle $ is the cycle structure of g (and h).

Proof If g and h are conjugates, then $h=y^{-1}gy$ for some $y\in S_n$ and therefore $y\in F(g,h)$ and $F(g,h)$ is nonempty. If $F(g,h)$ is nonempty, then there exists $y\in F(g,h)$ such that $g^{-1}yh=y$ or $g=y^{-1}hy$ , and so g and h are conjugates.

Suppose $h = y^{-1}g y$ for some $y \in S_n$ . We claim that if $z\in C(g)$ , then $zy \in F(g,h)$ . We need only to check that

$$ \begin{align*} g^{-1}zy h = zg^{-1}yh =zy \end{align*} $$

since $g^{-1}z = zg^{-1}$ . Define a map

$$ \begin{align*} \theta: \mathcal{C}(g) \to F(g,h) \end{align*} $$

by $\theta (z) = zy,$ which is valid since $zy\in F(g,h)$ . Clearly, $\theta $ is injective since $zy = z'y$ implies that $z=z'$ .

Next, for $x \in F(g,h)$ , note that $g^{-1}xh=x,$ or $xhx^{-1}=g$ . Let $z=xy^{-1}$ . Then

$$ \begin{align*} zgz^{-1} = x(y^{-1}gy)x^{-1} = xhx^{-1}=g, \end{align*} $$

and therefore $z\in C(g)$ . It is clear that $\theta (z)=\theta (xy^{-1})=xy^{-1}y=x$ and so $\theta $ is surjective. The second assertion now follows from Lemma 3.1.

We are now ready to give a new proof of (1.6).

Proof of (1.6)

Let $C_n$ be the subgroup of $S_n$ generated by the n-cycle $(1\ 2\ \cdots \ n).$ Consider the action $G=C_n \times C_n$ on $X = S_n$ given by $(g, h) \bullet x = g^{-1}x h$ . Indeed, this is a group action since

$$ \begin{align*} [(g_1, h_1)\cdot (g_2, h_2)] \bullet x &= (g_1g_2, h_1h_2) \bullet x = (g_1g_2)^{-1}x(h_1h_2) \\ &= g_2^{-1}(g_1^{-1} x h_1) h_2 = (g_2, h_2) \bullet [(g_1, h_1) \bullet x]. \end{align*} $$

By Theorem 2.1, the number of orbits N arising from G acting on $S_n$ is

(3.1) $$ \begin{align} N = \frac{1}{n^2} \sum_{(g,h) \in G} |\text{Fix}((g,h))|. \end{align} $$

Note that $\text {Fix}((g,h))=F(g,h)$ where $F(g,h)$ is the set defined in Lemma 3.2.

For an element $g\in G$ , we will use $o(g)$ to denote the order of g in G. We have seen that $F(g,h)$ is nonempty if and only if g and h are conjugate to each other. In other words, $F(g,h)$ is nonempty if and only if $o(g)=o(h)$ . Furthermore, $o(g)|n$ . Therefore, we may rewrite (3.1) as

(3.2) $$ \begin{align} N = \frac{1}{n^2} \sum_{d|n} \sum_{\substack{(g,h)\in G \\ o(g)=o(h)=d}} |F(g,h)|. \end{align} $$

Next, it is known that if $o(g)=d$ in $C_n$ , then g has cycle type $c(g)=( d,d,\ldots , d),$ where there are $n/d$ copies of d in $c(g)$ . By Lemma 3.2, we conclude that

$$ \begin{align*} |F(g,h)|=(n/d)! d^{n/d} \end{align*} $$

and rewrite (3.2) as

$$ \begin{align*} N = \frac{1}{n^2} \sum_{d|n} \varphi^2(d) d^{n/d} (n/d)!, \end{align*} $$

since there are precisely $\varphi ^2(d)$ elements $(g,h)\in G$ with $o(g)=o(h).$ The congruence (1.6) now follows immediately.

This new proof of (1.6) explains the presence of $(n/d)! d^{n/d}$ and $\varphi ^2(d)$ in (1.6).

This section is motivated by the articles of Evans [Reference Evans9] and András [Reference András1]. We are led to these articles because of our interest in generalizing Petersen’s proof of Wilson’s theorem [Reference Petersen15] found in Andrews’ book [Reference Andrews2, Section 3.3].

4 Some facts about arithmetic functions and András’ theorem

An arithmetic function f is a function from the set of positive integers to the set of complex numbers. One of the most important arithmetic functions is the Möbius function defined as follows.

Definition 4.1 Let $\mu (1)=1$ and for $\displaystyle n=\prod _{k=1}^m p_k^{\alpha _k},$ let

$$ \begin{align*} \mu(n) =\begin{cases} (-1)^m, \quad &\text{if } \alpha_k=1, 1\leq k\leq m, \\ 0, \quad &\text{otherwise.}\end{cases} \end{align*} $$

The Dirichlet product of two arithmetic functions is a binary operation defined as follows.

Definition 4.2 Let f and g be two arithmetical functions. We define the Dirichlet product of f and g, denoted by $f*g$ , as

$$ \begin{align*} (f*g)(n)=\sum_{d|n} f(d) g\bigg(\dfrac{n}{d}\bigg). \end{align*} $$

From now on, we will use $f*g(n)$ to represent $(f*g)(n)$ , removing the use of brackets. We will record a few facts regarding several arithmetic functions that we need for this article.

Lemma 4.1 For any $n\in {\mathbf Z}^+$ , let $u(n)=1$ , $\mathcal N(n)=n$ , and $I(n)=[1/n],$ where $[\cdot ]$ is the greatest integer function. Then:

  1. (1) $u*\mu (n)=I(n),$

  2. (2) $\mu *{\mathcal N}(n) =\varphi (n),$

  3. (3) $\mu {\mathcal N} * {\mathcal N}(n)=I(n).$

The proofs of Lemma 4.1(a)–(c) can be found in Apostol’s book [Reference Apostol3, Theorem 2.1], [Reference Apostol3, Theorem 2.3], and [Reference Apostol3, Theorem 2.17], respectively.

Lemma 4.2 Let f and g be two arithmetic functions. Then

$$ \begin{align*} f(n)=g*u(n) \end{align*} $$

if and only if

$$ \begin{align*} g(n)=f*\mu(n). \end{align*} $$

The proof of Lemma 4.2 can be found in [Reference Apostol3, Theorem 2.9].

Around 2011, András [Reference András1] revisited Evans’ work and discovered the following interesting result.

Theorem 4.3 Let $F(n)$ be an arithmetic function. Then

(4.1) $$ \begin{align} \sum_{d|n} \varphi(d) F(n/d)\equiv 0\quad \pmod{n} \end{align} $$

if and only if

(4.2) $$ \begin{align} \sum_{d|n}\mu(d) F(n/d) \equiv 0\quad \pmod{n}. \end{align} $$

András has a complete proof of the above, but (4.1) implies (4.2) was not presented in his article. We now give our proof of Theorem 4.3 using Lemma 4.1.

Proof Suppose (4.1) holds. Then there exists an integer-valued arithmetic function G such that

$$ \begin{align*} \varphi*F(n)= \mathcal N(n)G(n). \end{align*} $$

This implies that

(4.3) $$ \begin{align} \mu\mathcal{N} *\varphi*F(n) = \mu\mathcal{N}* \mathcal N(n)G(n). \end{align} $$

Applying Lemma 4.1(b) followed by Lemma 4.1(c), we may rewrite the left-hand side of (4.3) as

$$ \begin{align*} \mu {\mathcal N} * \varphi*F(n) = \mu {\mathcal N}*{\mathcal N} *\mu*F(n)= I*\mu*F(n)=\mu*F(n). \end{align*} $$

The right-hand side of (4.3) is

$$ \begin{align*} \mu {\mathcal N}*{\mathcal N} G(n) =\sum_{d|n} \mu(d) d \, \dfrac{n}{d}G\left(\dfrac{n}{d}\right) = n\sum_{d|n} \mu(d)G\left(\dfrac{n}{d}\right)\equiv 0\quad \pmod{n}. \end{align*} $$

Therefore, (4.2) holds.

Next, suppose (4.2) holds. Then

$$ \begin{align*} \mu*F(n) = {\mathcal N}(n)G(n) \end{align*} $$

for some integer-valued arithmetic function G. This implies that

(4.4) $$ \begin{align} {\mathcal N}*\mu* F(n) = {\mathcal N}*{\mathcal N} G(n). \end{align} $$

Using Lemma 4.1(b), we deduce that the left-hand side of (4.4) is

$$ \begin{align*} {\mathcal N}*\mu* F(n)=\varphi *F(n), \end{align*} $$

whereas the right-hand side of (4.4) is

$$ \begin{align*} {\mathcal N} * {\mathcal N} G(n) =\sum_{d|n} d\, \dfrac{n}{d}G\left(\dfrac{n}{d}\right) = n\sum_{d|n} G(n/d)\equiv 0\quad \pmod{n}. \end{align*} $$

Therefore, (4.1) holds.

András used Theorem 4.3 to deduce from (1.6) that

$$ \begin{align*} \sum_{d|n} \mu(d)\varphi(d)\left(\dfrac{n}{d}\right)!d^{n/d}\equiv 0\quad \pmod{n^2}. \end{align*} $$

We observe that András’ congruence is also a generalization of (1.3). If we apply Theorem 4.3 to (1.5), we deduce the new congruence

(4.5) $$ \begin{align} \sum_{d|n} \mu(d)\varphi(d) \left(\dfrac{n}{d}\right)!d^{n/d}a^{n/d}\equiv 0\quad \pmod{n^2}. \end{align} $$

Applying Theorem 4.3 one more time to (4.5), we conclude that

(4.6) $$ \begin{align} \sum_{d|n} \mu^2(d) \left(\dfrac{n}{d}\right)!d^{n/d}a^{n/d}\equiv 0\quad \pmod{n^2}. \end{align} $$

Both congruences (4.5) and (4.6) are also generalizations of (1.3).

In the next section, we give a generalization of (4.5) and hence generalizations of (1.5) and (4.6) using Theorem 4.3.

With Theorem 4.3, we can now conclude that the congruences

(4.7) $$ \begin{align} \sum_{d|n} \varphi(d) a^{n/d} \equiv 0\quad \pmod{n} \end{align} $$

and (1.7) are equivalent. Both (4.7) and (1.7) are generalizations of (1.1). We will now give a brief history of (4.7) and (1.7). Congruence (4.7) was discovered by MacMahon [Reference MacMahon11] using the following result of Moreau [Reference Moreau12, p. 313].

Theorem 4.4 Let n be a positive integer, and let

$$ \begin{align*} n=\alpha_1+\alpha_2+\cdots +\alpha_s, \end{align*} $$

where $\alpha _1,\alpha _2,\ldots ,\alpha _s$ are positive integers. Let $D=\text {gcd}(\alpha _1,\alpha _2,\ldots , \alpha _s).$ Then

$$ \begin{align*} \sum_{d|D} \varphi(d) \dfrac{(n/d)!}{(\alpha_1/d)!(\alpha_2/d)!\cdots (\alpha_s/d)!} \equiv 0\quad \pmod{n}. \end{align*} $$

The works of MacMahon and Moreau are mentioned in Riordan’s book [Reference Riordan16, p. 162, Problem 37]. The approach to these congruences in [Reference Riordan16] involves using the Redfield–Polya theorem (see Stanley’s book [Reference Stanley21, p. 394, Theorem 7.24.4]). Another proof of (4.7) was given by Gegenbauer [Reference Gegenbauer10]. He used Theorem 1.1 and the identity [Reference Apostol3, p. 26, Theorem 2.2]

(4.8) $$ \begin{align} \sum_{d|n} \varphi(d) = n\equiv 0\quad \pmod{n} \end{align} $$

to derive (4.7).

We now discuss (1.7). Congruence (1.7) in the case when a is a prime number is probably known to C.F. Gauss. The expression

$$ \begin{align*} \dfrac{1}{n}\sum_{d|n} \mu(d) p^{n/d} \end{align*} $$

counts the number of irreducible polynomials of degree n over the finite field of p elements (see Cox’s book [Reference Cox6, p. 300, Theorem 11.2.4]). This means that (1.7), after applying Dirichlet’s theorem of primes in arithmetic progression, is true for any integer n such that $(a,n)=1$ . According to Dickson [Reference Dickson7, p. 84], (1.7) was first stated by Serret [Reference Serret19, p. 262] in 1855. One of the simplest proofs of (1.7) can be found in Szele’s article [Reference Szele22] and Gegenbauer’s article [Reference Gegenbauer10]. See also an exercise in Rose’s book [Reference Rose18, p. 55, Problem 11].

Another proof of (1.7), using Theorem 2.1, relies on counting the number of orbits with exactly n elements for the group ${\mathbf Z}/n{\mathbf Z}$ acting on X, the set of all necklaces obtained from beads which can be colored using a colors. Note that $|X|=a^n$ . Let $N_m$ be the number of orbits with exactly m elements. Note that by (2.1), $N_m$ is nonempty if and only if $m|n$ . Therefore,

$$ \begin{align*} a^n=\sum_{d|n} dN_d. \end{align*} $$

Applying Lemma 4.2, we deduce that

$$ \begin{align*} nN_n=\sum_{d|n}\mu(d) a^{n/d}, \end{align*} $$

and (1.7) follows. For yet another proof of (1.7) using periodic points of a function, see [Reference András1, p. 268].

5 A generalization of the Moser–Moser congruence

In this section, we derive the following generalization of the Moser–Moser congruence.

Theorem 5.1 Let $n, a$ , and b be positive integers. Then

(5.1) $$ \begin{align} \sum_{d|n} \varphi^2(d) \left(\dfrac{n}{d}\right)! d^{n/d} a^{n/d} b^d \equiv 0\quad \pmod{n^2}. \end{align} $$

It is immediate that (1.5) is a special case of (5.1) with $b=1$ .

By Theorem 1.1, we see that congruence (5.1) follows immediately from the following.

Theorem 5.2 Let n and b be positive integers. Then

(5.2) $$ \begin{align} \sum_{d|n} \varphi^2(d) \left(\dfrac{n}{d}\right)! d^{n/d} b^d \equiv 0\quad \pmod{n^2}. \end{align} $$

We should note the difference between (5.2) and (1.5). Our congruence (5.2) is a generalization of (1.4) in exactly the same manner that (1.5) is a generalization of (1.3). We have not been able to find a proof of (5.2) which involves Theorem 2.1.

Proof Let $\displaystyle n=\prod _{j=1}^s p_j^{\alpha _j}.$ Our aim is to show that for $1\leq j\leq s$ ,

(5.3) $$ \begin{align} \sum_{d|n}\mu(d)\varphi(d)\left(n/d\right)!d^{n/d}a^d\equiv 0\quad \pmod{p_j^{2\alpha_j}}. \end{align} $$

We note that it suffices to prove (5.3) for a fixed j. Let $p=p_1$ and $\alpha =\alpha _1$ . We first observe that the presence of $\mu (n)$ implies that

$$ \begin{align*}\sum_{d|n}\mu(d)\varphi(d)\left(n/d\right)!d^{n/d}a^d =\sum_{d|p p_2\cdots p_s}\mu(d)\varphi(d)\left(n/d\right)!d^{n/d}a^d.\end{align*} $$

We pair up the divisors of $pp_2\cdots p_s$ as $p\nu $ and $\nu $ , where $(\nu ,p)=1$ . We claim that for each such pair of divisors, the terms corresponding to them satisfy

(5.4) $$ \begin{align} \mu(p\nu)\varphi(p\nu)(p^{\alpha-1}\ell/\nu)!(p\nu)^{p^{\alpha-1}\ell/\nu}a^{p\nu}&+\mu(\nu)\varphi(\nu) (p^{\alpha}\ell/\nu)!\nu^{p^{\alpha}\ell/\nu} a^{\nu}\\ &\equiv 0\quad \pmod{p^{2\alpha}},\notag\end{align} $$

where $\ell $ is given by $\ell =n/p^{\alpha }$ . Congruence (5.4) would imply (5.3). Note that from (5.4), we find that

$$ \begin{align*} & \mu(p\nu)\varphi(p\nu)(p^{\alpha-1}\ell/\nu)!(p\nu)^{p^{\alpha-1}\ell/\nu} a^{p\nu}+\mu(\nu)\varphi(\nu)(p^{\alpha}\ell/\nu)!\nu^{p^{\alpha}\ell/\nu} a^{\nu}\\ &\quad =\mu(\nu)\varphi(\nu)\left(-\varphi(p)(p^{\alpha-1}\ell/\nu)! (p\nu)^{p^{\alpha-1}\ell/\nu}a^{p\nu}+(p^{\alpha}\ell/\nu)!\nu^{p^{\alpha}\ell/\nu} a^{\nu}\right). \end{align*} $$


$$ \begin{align*} S_1=(p^{\alpha}\ell/\nu)!\nu^{p^{\alpha}\ell/\nu} a^{\nu}\quad\text{and}\quad S_2=\varphi(p)(p^{\alpha-1}\ell/\nu)!(p\nu)^{p^{\alpha-1}\ell/\nu} a^{p\nu}. \end{align*} $$

It suffices to show that

(5.5) $$ \begin{align} S_1-S_2\equiv 0\quad \pmod{p^{2\alpha}}. \end{align} $$

We divide our arguments into the following cases, according to the values of $\ell /\nu $ , $\alpha $ , and p.

Case 1: $\ell /\nu \geq 2$ . We note that $(p^{\alpha } \ell /\nu )! $ contains the factors $2p^{\alpha }$ and $p^{\alpha }$ . Therefore, $p^{2\alpha }$ is a factor of $S_1$ . On the other hand, we see that

$$\begin{align*}p^{\alpha-1}\frac{\ell}{\nu} \geq 2^{\alpha} \geq 2\alpha. \end{align*}$$

Therefore, $p^{2\alpha }$ divides $p^{p^{\alpha -1} \ell /\nu }$ , and so is a factor of $S_2$ . Hence, (5.5) is true.

Case 2a: $\ell /\nu =1$ and $\alpha =1$ . In this subcase, we find that

$$ \begin{align*} S_1-S_2=p!\nu^{p}a^{\nu}-(p-1) \nu p a^{p\nu} =p((p-1)!\nu^p a^{\nu} -(p-1)\nu a^{p\nu})\equiv 0\quad \pmod{p^2}, \end{align*} $$

where we have used Wilson’s theorem and Fermat’s Little Theorem.

Case 2b(i): $\ell /\nu =1$ , $\alpha =2$ and $p=2$ . For these values, we see that

$$ \begin{align*} S_1-S_2=4!\nu^{4}a^{\nu}- 2!\nu^2 2^2 a^{2\nu} =2^3\nu^2a^{\nu}(3\nu^2 -a^{\nu})\equiv 0\quad \pmod{2^4} \end{align*} $$

since $\nu ^2a^{\nu }(3\nu ^2-a^{\nu })$ must be even.

Case 2b(ii): $\ell /\nu =1$ , $\alpha =2$ , and $p\geq 3$ . We note that $(p^2)!$ contains the factors $p^2$ , $2p$ , and p. Hence, $p^4$ divides $S_1$ . On the other hand, clearly, $p^3$ divides $(p\nu )^p$ and so $p^4$ divides $S_2$ .

Case 2c: $\ell /\nu =1$ and $\alpha \geq 3$ . We note that $(p^{\alpha })!$ contains the factors $p^{\alpha }$ , $p^{\alpha -1}$ , and p. Hence, $p^{2\alpha }$ divides $S_1$ . On the other hand,

$$\begin{align*}p^{\alpha-1} \geq 2^{\alpha-1} \geq 2(\alpha-2). \end{align*}$$

Therefore, $p^{2\alpha -2}$ divides $p^{p^{\alpha -1}}$ . Also, clearly, $p^2|p^{\alpha -1}$ . Collectively, we see that $p^{2\alpha }$ divides $S_2$ .

Thus, all cases of the congruence (5.5) are proved, and this completes the proof of the theorem.

Once again, by Theorem 4.3, we deduce the following theorem.

Theorem 5.3 Let n and b be positive integers. Then

(5.6) $$ \begin{align} \sum_{d|n} \mu(d) \varphi(d) \left(\dfrac{n}{d}\right)! d^{n/d} b^d a^{n/d}\equiv 0\quad \pmod{n^2}. \end{align} $$

By using Theorem 4.3 yet again, we deduce from (5.6) the following congruence:

$$ \begin{align*} \sum_{d|n} \mu^2(d) \left(\dfrac{n}{d}\right)! d^{n/d} b^d a^{n/d} \equiv 0\quad \pmod{n^2}.\end{align*} $$

6 Analogues of Gegenbauer’s theorem

In this final section, we will derive a generalization of Gegenbauer’s theorem.

Theorem 6.1 Let n be a positive integer. Let $F:{{\mathbf Z}}^+\rightarrow {\mathbf Z}$ and G be an arithmetic function. Suppose

(6.1) $$ \begin{align} \sum_{d|n}\mu(d)G(n/d) \equiv 0\quad \pmod{n}. \end{align} $$


(6.2) $$ \begin{align} \sum_{d|n} F(d)\equiv 0\quad \pmod{n}, \end{align} $$


$$ \begin{align*}\sum_{d|n} F(d) G(n/d)\equiv 0\quad \pmod{n}. \end{align*} $$

The function $G(n)$ which appears in Theorem 6.1 is known as a Dold sequence [Reference Byszewski, Graff and Ward4, Definition 2.1].

Let a be a positive integer, and let

$$ \begin{align*}G(k)=\begin{cases}a^{k},\quad\text{if } k|n, \\ 0, \quad\text{otherwise.}\end{cases}\end{align*} $$

Then since (1.7) holds, we see that Theorem 6.1 implies Theorem 1.1.

Our proof of Theorem 6.1 follows Gegenbauer’s proof of Theorem 1.1. Another proof of Theorem 6.1 can be found in a recent article of Wójcik [Reference Wójcik23]. The proof given there is dependent on the equivalence of Newton sequence and Dold sequence established by Du, Huang, and Li [Reference Du, Huang and Li8].

Proof of Theorem 6.1

We write (6.1) and (6.2) as

$$ \begin{align*} \mu*G(n)=\mathcal NH(n) \end{align*} $$


(6.3) $$ \begin{align} F*u(n) = \mathcal NK(n),\end{align} $$

respectively, where $H(\ell ), K(\ell )\in {\mathbf Z}$ for all $\ell \in {\mathbf Z}^+$ . From (6.3) and Lemma 4.2, we deduce that

$$ \begin{align*}F(n)=\mathcal NK *\mu(n).\end{align*} $$

This implies that

$$ \begin{align*} F*G(n) &= \mathcal NK*\mu * G(n) = \mathcal NK* \mathcal NH (n)\\ &=\sum_{d|n}dH(d)\dfrac{n}{d}K\left(\dfrac{n}{d}\right) = n H*K(n) \equiv 0\quad \pmod{n},\end{align*} $$

and the proof of Theorem 6.1 is complete.

There are already several $G(n)$ which we can choose from the congruences we discussed in the previous sections. For example, we could identify $G(n)$ from (5.6) and deduce using Theorem 6.1 that if (6.2) holds, then

(6.4) $$ \begin{align} \sum_{d|n} F(d) \varphi(d) \left(\dfrac{n}{d}\right)! d^{n/d} b^d \equiv 0\quad \pmod{n^2}.\end{align} $$

We may also apply Theorem 6.1 to a variant of Theorem 4.4, which we state as follows (with $\varphi $ replaced by $\mu $ via Theorem 4.3).

Theorem 6.2 Let n be a positive integer, and let

$$ \begin{align*}n=\alpha_1+\alpha_2+\cdots +\alpha_s,\end{align*} $$

where $\alpha _1,\alpha _2,\ldots ,\alpha _s$ are positive integers. Let $D=\text {gcd}(\alpha _1,\alpha _2,\ldots , \alpha _s).$ Then

(6.5) $$ \begin{align} \sum_{d|D} \mu(d) \dfrac{(n/d)!}{(\alpha_1/d)!(\alpha_2/d)!\cdots (\alpha_s/d)!} \equiv 0\quad \pmod{n}.\end{align} $$

The function $G(n)$ in (6.1) can now be identified from (6.5), allowing us to deduce from Theorem 6.1 that if (6.2) holds, then

(6.6) $$ \begin{align} \sum_{d|D} F(d) \dfrac{(n/d)!}{(\alpha_1/d)!(\alpha_2/d)!\cdots (\alpha_s/d)!} \equiv 0\quad \pmod{n}.\end{align} $$

We may use combinations of Theorem 1.1, (6.4), and (6.6) to derive many new congruences. For example, we have

$$ \begin{align*}\sum_{d|D} \varphi^2(d) \dfrac{(n/d)!}{(\alpha_1/d)!(\alpha_2/d)!\cdots (\alpha_s/d)!}\left(\dfrac{n}{d}\right)! d^{n/d} b^da^{n/d}\equiv 0\quad \pmod{n^2}.\end{align*} $$


We are very grateful to Professors G. E. Andrews, W. Zudilin, and Kuo-Jye Chen for their encouragement. We thank Professor P. Moree for helping us locate L. Moser’s paper. We also thank Professors T. J. Evans and S. András for answering our queries with regard to their works. Finally, we thank the referee for the references [Reference Byszewski, Graff and Ward4, Reference Wójcik23].


András, S., A combinatorial generalization of Wilson’s theorem . Aust. J. Combin . 49(2011), 265272.Google Scholar
Andrews, G. E., Number theory, W. B. Saunders Company, Philadelphia, PA, 1971.Google Scholar
Apostol, T. M., Introduction to analytic number theory, Undergradute Text in Mathematics, Springer, New York, 1976.Google Scholar
Byszewski, J., Graff, G., and Ward, T., Dold sequences, periodic points, and dynamics . Bull. Lond. Math. Soc. 53(2021), 12631298.CrossRefGoogle Scholar
Cameron, P. J., Combinatorics: topics, techniques, algorithms, Cambridge University Press, Cambridge, 1994.Google Scholar
Cox, D. A., Galois theory, John Wiley & Sons, Hoboken, NJ, 2004.CrossRefGoogle Scholar
Dickson, L. E., History of the theory of numbers, Carnegie Institute of Washington, Washington, DC, 1919. Reprinted by Chelsea Publishing, New York, 1971.Google Scholar
Du, B. S., Huang, S. S., and Li, M. C., Newton, Fermat, and exactly realizable sequence . J. Integer Seq. 8(2005), Article no. 05.1.2.Google Scholar
Evans, T. J., On some generalizations of Fermat’s, Lucas’s and Wilson’s theorems . Ars Combin. 79(2006), 189194.Google Scholar
Gegenbauer, L., Überein theorem des Herrn MacMahon . Monatsh. Math. Phys. 11(1900), 287288.CrossRefGoogle Scholar
MacMahon, P. A., Applications of the theory of permutations on circular procession to the theory of numbers . Proc. Lond. Math. Soc. 23(1891–2), 305313.CrossRefGoogle Scholar
Moreau, C., Sur les permutations circulaires distincts . Nouv. Ann. Math. 11(1872), 309314.Google Scholar
Moser, L., On the theorems of Wilson and Fermat . Scripta Math. 22(1956), 288.Google Scholar
Moser, W. O. J., A (modest) generalization of the theorems of Wilson and Fermat . Can ad. Math. Bull. 33(1990), 253256.CrossRefGoogle Scholar
Petersen, J., Beviser for Wilsons og Fermats Theoremer . Tidsskrift Math. (3) 2(1872), 6465.Google Scholar
Riordan, J., Introduction to combinatorial analysis, John Wiley & Sons, New York, 1958.Google Scholar
Robinson, D. J. S., Abstract algebra, an introduction with applications. 2nd ed., De Gruyter, Berlin, 2015.CrossRefGoogle Scholar
Rose, H. E., A course in number theory. 2nd ed., Oxford University Press, Oxford, 1994.Google Scholar
Serret, J. A., Théorème de Fermat généralisé . Nouv. Ann. Math. 14(1855), 261262.Google Scholar
Sierpinski, W., Elementary theory of numbers, North-Holland Mathematical Library, 31, Polish Scientific Publishers, Warsaw, 1987.Google Scholar
Stanley, R. P., Enumerative c ombinatorics . Vol. 2, Cambridge Studies in Advanced Mathematics, Cambridge University Press, Cambridge, 1999.CrossRefGoogle Scholar
Szele, T., Une généralization de la congruence de Fermat . Mat. Tidsskr. B (1948), 5759.Google Scholar
Wójcik, K., Newton sequence and Dirichlet convolution. Integers 21(2021), Article no. A63.Google Scholar