The exercise presented here connects the most important results seen so far. It is a summary.

Exercise.

Find all integers such that

Warning:

As always, if you read the solution before trying to solve the exercise yourself, you are likely wasting your time.

Solution.

Step 1: Linearize

I use the Euclidean algorithm to find the inverse of mod . First, I iterate the Q-R formula:

StepEquation
1
2
3
4
5 (optional)

Second, I plug the remainders back in reverse order:

StepEquation
4
3
2
1

Reducing mod , I have , hence the inverse is . Substituting , the congruence to solve becomes

Step 2: Divide

Factoring . By the Chinese remainder theorem, solving the above is equivalent to solving the system

The middle congruence easily reduces to . And the only integer whose square is 1 mod 2 is 1, thus .

The right congruence simplifies to .

Hint.

The latter can easily be solved by cases since is small. However, if the prime factor were large, such as the case of , guessing and checking is unfeasible.

By Fermat’s little theorem, , and since ,

In the lectures I prove that the only square roots of 1 mod a prime are . Then, .

Now, again by Fermat’s little theorem, . Therefore, the system reduces to

Hint.

What do the commas in the last two congruences mean precisely? I am no longer trying to solve one system, but four. Here is the precise logical statement:

Step 3: Conquer

Clearly solves one of the systems, so by the Chinese remainder theorem, is the only solution mod to the first system. is a solution to another one of the systems.

Since the first congruence only says is odd, I omit it to reduce clutter. The remaining two systems are

The top one is solved by taking the second congruence as for some , and plugging it into the second one: , from where for some . Hence, ; but I want to be odd, so I can pick and get .

Reflect.

Any value of that makes odd produces a valid solution . You have understood how to solve systems of congruences when you can explain why. Also, why did I plug the second congruence into the first one and not the other way around?

The bottom one is solved exactly the same way to get .

Step 4: Multiply

By the Chinese remainder theorem, the final answer is

so the set of all integer solutions is


Exercise.

What is the shortest computer program you can write that solves this problem? What about the fastest?

Exercise.

Try solving the same initial congruence but with instead of . Do you expect to find more solutions or fewer mod ?