[Verse 1]
Take the integers, divide by n
Group them up where remainders blend
Zero through n minus one they go
Residue classes in a row
Bracket zero, bracket one
Bracket two until we're done
Z mod n Z is what we call
This algebraic structure for us all
[Chorus]
Ring of residues, modulo n
Add and multiply, round again
When the modulus is prime you see
Every element finds its key
Multiplicative inverse waiting there
Extended Euclidean shows you where
Ring of residues, remember this tune
Prime makes a field, composite won't do
[Verse 2]
Addition wraps around the clock
When you hit n, back to the start you rock
Multiplication works the same
Take the remainder, that's the game
But here's the magic, here's the test
When n is prime, we get the best
Every non-zero element you choose
Has an inverse it cannot lose
[Chorus]
Ring of residues, modulo n
Add and multiply, round again
When the modulus is prime you see
Every element finds its key
Multiplicative inverse waiting there
Extended Euclidean shows you where
Ring of residues, remember this tune
Prime makes a field, composite won't do
[Bridge]
Composite numbers break the spell
Some elements can't divide so well
Zero divisors lurk around
But primes keep fields safe and sound
GCD algorithms pave the way
To find inverses every day
[Outro]
From zero up to n minus one
Residue classes, we are done
Prime or composite, now you know
How Z mod n Z will always go