Nib explains · Number theory

Fermat's Ladder

Square, add one, repeat. The first five rungs are all prime, and then the primes stop. The 34th rung, F33, has about 2.6 billion digits, and nobody knows whether it is prime.

F33 in binary:  1000000000000 … 8,589,934,591 zeros … 0000000000001
2233 + 1
the number itself
2,585,827,973
decimal digits
F5 … F32
all known to be composite
unknown
status of F33

Nib says: You've met one of these numbers before. The fifth rung, 65,537, is the public exponent inside most RSA keys on the internet. It's prime, and in binary it's a one, fifteen zeros and a one, which makes it quick to use. This page is about its much bigger cousins. Every toy runs in your browser.

Five primes, then a surprise

Fermat numbers are Fn = 22n + 1. Each rung comes from the last: take one away, square it, add one back. So Fn+1 = (Fn − 1)2 + 1. Starting from 3, you get 5, 17, 257 and 65,537, all prime. In 1640 Fermat guessed the pattern held forever.

Climb the ladder

The first five rungs are below. Press Next rung to keep going.

In 1732 Euler found that the sixth rung, F5 = 4,294,967,297, equals 641 × 6,700,417. Since then every Fermat number anyone has been able to test has turned out composite.

Find a factor without building the giant

To ask whether a prime p divides Fn, you only need Fn's remainder when divided by p. Start at 2 and square n times, keeping only the remainder mod p each time (that's modular arithmetic). If you land on p − 1, then 22n ≡ −1 mod p, and p divides Fn. Every number along the way stays smaller than p².

Euler and Lucas also showed that any factor has the shape p = k · 2n+2 + 1. So the search runs over k, and each test costs only n squarings.

Factor finder

Pick a Fermat index n and how far to search. Try n = 5 to find Euler's 641, or n = 12, which has three small factors.

Example: n = 5 finds Euler's 641 instantly.

Run the same idea in C over every k up to two million (keeping p under 263 so it fits in one machine word) and it finishes in under a minute. It turns up factors of 23 different Fermat numbers between F5 and F55, among them F32, which has about 1.3 billion digits. Here is the smallest factor it found for each:

Fnfactor p= k · 2n+2 + 1

The 1/k law

Take any prime of the form p = k · 2m + 1 with k odd. It divides some Fermat number exactly when 2 is a k-th power residue mod p, and for a "random" number that happens about once in k tries. We tested every such prime with odd k below 200 and 2 ≤ m ≤ 300.

1,049
candidate primes tested
27
divide a Fermat number
30.4
predicted by the 1/k law

Share of candidates that divide a Fermat number

Odd k from 1 to 21. (k = 19 is left out: it has only three candidate primes.) Hover or tap a bar for the counts.

observedpredicted, 1/k

This is why every factor search hammers small k first: those are the best odds. The hits it turns up are tiny factors of unimaginably large numbers. 5 · 2127 + 1 divides F125, and 7 · 2290 + 1 divides F284.

Gauss and the form x² + 27y²

For k = 3 the coin flip has an exact rule. Gauss showed that 2 is a cube mod p exactly when p can be written as x² + 27y², a quadratic form. So "does 3 · 2m + 1 divide a Fermat number?" becomes a question about a shape on a grid. We checked every prime 3 · 2m + 1 with 2 ≤ m ≤ 300.

mdivides a Fermat numberp = x² + 27y²

Fourteen for fourteen. The geometry gives exactly the same answer as the arithmetic. It's a real change of viewpoint, but each candidate still has to be checked one at a time.

Why F33 needs the whole giant

Finding a factor proves Fn composite. Without one, the only known test is Pépin's test (1877): Fn is prime exactly when 3(Fn−1)/2 ≡ −1 mod Fn. Now the clock is the giant itself, so every one of the 2n − 1 squarings works on a number as large as Fn.

Pépin's test, timed in your browser

Each step up roughly doubles the number of squarings and doubles the size of each number. Start at n = 10 and work up. n = 14 takes a while.

Press Run Pépin.

For F33 that means about 8.6 billion squarings of 8.6-billion-bit numbers. Even with the fastest multiplication methods, that is far beyond routine computing today, which is why F33 remains open.

Is there a better domain?

Changing the setting has cracked hard cases before. Lenstra's elliptic curve method (1985) finds factors by working on elliptic curves mod p instead of with ordinary multiplication mod p. Each new curve gives a hidden factor another chance to fall out, and it is how Richard Brent finished factoring F10 and F11. The Lucas–Lehmer test for Mersenne numbers and Pépin's test for Fermat numbers are earlier versions of the same idea: a special structure turns "is it prime?" into one clean chain of squarings.

Nib says: This case is still open. The question is whether some setting exists where the status of F33 falls out without anyone ever handling a 2.6-billion-digit number. Nobody knows. It's a good question to keep asking.

Words on this page

Tap any word with a dotted gold underline to see what it means. Here they all are in one place.

Three things to keep

Check yourself

How can you test whether 641 divides F5 without ever writing F5 down?

Start at 2 and square five times, keeping only the remainder mod 641 after each step. You land on 640, which is −1 mod 641, so 641 divides 232 + 1. No number along the way is bigger than 641².

The factor finder searched every k up to a million and found nothing. Does that mean Fn is prime?

No. The factor might have a larger k. Only a primality test like Pépin's can show Fn is prime, and that needs arithmetic on the whole number.

Why do factor hunters try small k first?

A prime k · 2m + 1 with k odd divides some Fermat number with chance about 1/k. Small k gives the best odds per test.

Go deeper