So you think you’re a math whiz. You storm into parties armed with math’s most flamboyant tricks. You can recite the digits of π and *e* to 50 digits—whether in base 10 or 12. You can calculate squares with ease, since you’ve mastered the difference of squares x^{2} – y^{2} = (x + y)(x – y). In tackling 57^{2}, simply notice that 57^{2} – 7^{2} = (57 + 7)(57 – 7) = 64*50 = 3200. Adding 7^{2} to both sides gives 57^{2} = 3249.

You can also approximate square roots using the truncated Taylor series √*x* ≈ c + (x – c^{2})/(2c) where c^{2 }is the closest perfect square less than or equal to x. So √17 ≈ 4 + (17 – 16)/(2*4) = 4.125, whereas √17 = 4.123105 . . ..^{
}

But do you know what number theory is? It’s not taught in high school, and everyone’s repertoire of math tricks needs some number theory. Mastering modular arithmetic—the first step in number theory—will make you the life of the party. Calculating 83 mod 7 just means find the remainder after dividing by 7: 83 = 11*7 + 6, so 83 ≡ 6 mod 7. But it’s actually easier since 83 = 7*12 + (-1), so 83 ≡ -1 ≡ 6 mod 7. Modular arithmetic reveals the secrets of divisibility. Everybody knows the trick to see whether 3 divides a number; you just add the digits and check if 3 divides that number. But the reasoning is obvious when you write *m *= 10^{n}*a*_{n} + 10^{n}^{-1}*a*_{n}_{-1} + . . . + 10*a*_{1} + *a*_{0} where the *a*_{i} are the digits of *m*. Each 10* ^{k}* has a remainder of 1 modulo 3 so

*m*≡

*a*

_{n}+

*a*

_{n}

_{-1}+ . . . +

*a*

_{1}+

*a*

_{0}mod 3. Using this method generates tricks for other integers.

For instance, if 13 divides *m*, then 13 divides *a*_{0} – 3*a*_{1} – 4*a*_{2} – *a*_{3} + 3*a*_{4} + 4*a*_{5} + a_{6} – 3*a*_{7} – 4*a*_{8 }+ . . . and the pattern continues. This is because

10 ≡ -3 mod 13,

10^{2} ≡ 10*10 ≡ (-3)(-3) ≡ 9 ≡ -4 mod 13,

10^{3 }≡ 10^{2}*10 ≡ (-4)(-3) ≡ 12 ≡ -1 mod 13,

10^{4} ≡ 10^{3}*10 ≡ (-1)*(-3) ≡ 3 mod 13,

10^{5 }≡ 10^{4}*10 ≡ 3*(-3) ≡ -9 ≡ 4 mod 13,

and 10^{6 }≡ 10^{5}*10 ≡ 4*(-3) ≡ -12 ≡ 1 mod 13.

From 10^{6} and onwards the pattern repeats. In fact, calculating 10* ^{n}* mod

*k*for successive

*n*will reveal the divisibility rule for

*k*.

Then comes Fermat’s little theorem, the key to solving seemingly impossible calculations.

The theorem states for a prime *p* and integer *a* that *a ^{p }*≡

*a*mod

*p*. If p doesn’t divide a, then

*a*

^{p}^{ -1}≡ 1 mod

*p*. I’ll illustrate the power of this little result in a computation. Let’s find 2

^{371 }mod 5. We’ll be using 2

^{4}≡ 1 mod 5, which we get from Fermat’s little theorem. Now 2

^{371}= 2

^{368}2

^{3}=(2

^{4})

^{92}2

^{3}, so by the theorem, 2

^{371}= (2

^{4})

^{92}2

^{3}≡ 1

^{92}2

^{3 }≡ 1*2

^{3}≡ 8 ≡ 3 mod 5. Exploiting Fermat’s little theorem can impress your friends, but try to avoid questions. Computing residues modulo a composite number—calculating

*b*mod

*n*for a composite number

*n*—may require paper and ruin the magic.

Leonhard Euler proved a more general version of Fermat’s little theorem; it’s called the Euler-Fermat theorem. This theorem isn’t for parties; explaining it to the non-mathematically inclined will always require paper and some time. Nonetheless, it will impress at dinner if you have a napkin and pen.

Understanding this theorem requires Euler’s totient function *φ*(*n*).

The number *φ*(*n*) for some *n* is the number of positive integers coprime with *n* that are less than or equal to *n*. Two numbers *a* and *b* are coprime if their greatest common factor is one. Hence 14 and 3 are coprime because their biggest shared factor is 1, but 21 and 14 aren’t coprime because they have a common divisor of 7. Moreover, *φ*(14) = 6 because 14 has six numbers less than or equal to it that are coprime with it: 1, 3, 5, 9, 11, and 13. Notice that if *p* is prime, *φ*(*p*) = *p* – 1 because every number less than *p* is coprime with *p*.

Now the Euler-Fermat theorem states that *a*^{φ}^{(}^{n}^{)} ≡ 1 mod *n*, which looks similar to *a*^{p}^{ -1} ≡ 1 mod *p* for a prime *p*. In fact, if *n *= *φ*(*p*) = *p* – 1 for a prime *p*, the theorem reduces to Fermat’s little theorem.^{
}

Fermat’s little theorem has another generalization, Lagrange’s theorem. Joseph-Louis Lagrange was Euler’s student. Lagrange’s theorem generalizes both the previous theorems and doesn’t even require numbers. But due to the required background in group theory, I won’t go over the theorem. You can find links to more information on Lagrange’s theorem below.

Remember, a math whiz doesn’t need props like a magician does. Hook your audience with some modular arithmetic, and reel the people in with Fermat’s little theorem. If you want to get complicated, the most you’ll need is a pen and some paper.

Sources and cool stuff:

Math tricks: http://www.businessinsider.com/x-math-party-tricks-that-will-make-you-a-rockstar-2013-6?op=1

Modular arithmetic: http://nrich.maths.org/4350

Proof of Fermat’s little theorem: https://primes.utm.edu/notes/proofs/FermatsLittleTheorem.html

Euler-Fermat theorem and its proof: http://www.artofproblemsolving.com/Wiki/index.php/Euler%27s_Totient_Theorem

Lagrange’s theorem (only for the brave): http://cims.nyu.edu/~kiryl/teaching/aa/les102903.pdf

Fermat’s bio: http://www-history.mcs.st-and.ac.uk/Biographies/Fermat.html

Lagrange’s bio: http://www-history.mcs.st-and.ac.uk/Biographies/Lagrange.html

Number theory textbooks: Gordan Savin’s *Numbers**, Groups, and Cryptography* and George E. Andrews’s *Number Theory*

Interesting sources of math tricks and problems: Paul Zeitz’s *The* Art,* Craft of Problem Solving* and *The USSR Olympiad Problem Book*, and *What is Mathematics* by Richard Courant and Herbert Robbins