---
title: "Remainder of 28! + 27! + 26! Modulo 31 via Wilson's Theorem"
organization: "NityaDhi Digital Mathematics Lab (Asa Edtech Private Limited)"
url: "https://www.nityadhi.com/problems/hard-olympiad-nt-w1-modular-wilson-factorial-sum"
board: "Olympiad"
grade: "Olympiad"
published_at: "2026-11-29T13:30:00+05:30"
---

# Remainder of 28! + 27! + 26! Modulo 31 via Wilson's Theorem

Find the remainder when $28! + 27! + 26!$ is divided by $31$.

## Textbook Solution

Since $31$ is prime, Wilson's Theorem states that $30! \equiv -1 \pmod{31}$.
Factor the expression first to minimize modular inversions:
$$28! + 27! + 26! = 26!(28 \cdot 27 + 27 + 1) = 26!(28 \cdot 27 + 28) = 26! \cdot 28^2.$$
Wait: $28 \cdot 27 + 28 = 28(27 + 1) = 28^2$! Let's verify: $756 + 28 = 784 = 28^2$.

Now compute $26! \pmod{31}$ from Wilson's Theorem:
$$30! = 30 \cdot 29 \cdot 28 \cdot 27 \cdot 26! \equiv (-1)(-2)(-3)(-4) \cdot 26! = 24 \cdot 26! \equiv -1 \pmod{31}.$$
Notice $24 \equiv -7 \pmod{31}$, so $-7 \cdot 26! \equiv -1 \pmod{31} \implies 7 \cdot 26! \equiv 1 \pmod{31}$.
Since $7 \times 9 = 63 = 2(31) + 1 \equiv 1 \pmod{31}$, we obtain:
$$26! \equiv 9 \pmod{31}.$$
Next, compute $28^2 \pmod{31}$:
$$28 \equiv -3 \pmod{31} \implies 28^2 \equiv (-3)^2 = 9 \pmod{31}.$$
Therefore:
$$28! + 27! + 26! \equiv 9 \cdot 9 = 81 = 31 \times 2 + 19 \equiv 19 \pmod{31}.$$
The remainder is **$19$**.

## Vedic Shortcut

Factor $26!$ immediately to turn a sum of three factorials into a square times one factorial:
$$26!(28 \cdot 27 + 27 + 1) = 26! \cdot 28(27 + 1) = 26! \cdot 28^2.$$
And use negative residues in Wilson's Theorem:
$(-1)(-2)(-3)(-4) \cdot 26! = 24 \cdot 26! \equiv -1 \pmod{31} \implies 7 \cdot 26! \equiv 1 \pmod{31}$.
Since $31 \times 2 + 1 = 63 = 7 \times 9$, $26! \equiv 9 \pmod{31}$.
Finally $9 \times (-3)^2 = 81 \equiv$ **$19$** $\pmod{31}$.

## Common Mistakes

- **Using $(p-1)! \equiv 1$ instead of $-1$**: Wilson's theorem gives $30! \equiv -1 \pmod{31}$, not $+1$.
- **Computing $28!, 27!, 26!$ separately with three modular inversions**: Factoring $26!(28 \cdot 27 + 27 + 1) = 26! \cdot 28^2$ avoids extra inversions and algebra errors.