This problem from China is almost 2000 years old: Find a number that when divided by 3 gives a remainder of 1, when divided by 5 gives a remainder of 4, and when divided by 7 gives a remainder of 2.

divided by 3 gives a remainder of 1 :

4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 ...
when divided by 5 gives a remainder of 4 :
4 9 14 19 24 29 34 39 43 49 53 59 ...
when divided by 7 gives a remainder of 2 :
2 9 16 23 30 37 44 51 58 ...

nothing yet, so keep going

40.43/3

To solve this problem, we can use the Chinese Remainder Theorem (CRT). The Chinese Remainder Theorem states that there exists a unique solution to a system of congruences if the moduli are pairwise coprime (meaning they have no common factors).

In this case, we have three congruences:
1. x ≡ 1 (mod 3)
2. x ≡ 4 (mod 5)
3. x ≡ 2 (mod 7)

To find the solution, we can follow these steps:

1. Find the product of all the moduli. In this case, it is 3 * 5 * 7 = 105.

2. For each congruence, divide the product by the modulus to get the "partial product." For the first congruence (x ≡ 1 (mod 3)), the partial product is 105 / 3 = 35. The other partial products are 105 / 5 = 21 and 105 / 7 = 15.

3. Find the modular inverse of each partial product with respect to its corresponding modulus. The modular inverse of a number a (mod n) is a number x such that (a * x) ≡ 1 (mod n). In this case, we need to find the modular inverses of 35 (mod 3), 21 (mod 5), and 15 (mod 7).

- The modular inverse of 35 (mod 3) is 2, because (35 * 2) ≡ 1 (mod 3).
- The modular inverse of 21 (mod 5) is 1, because (21 * 1) ≡ 1 (mod 5).
- The modular inverse of 15 (mod 7) is 1, because (15 * 1) ≡ 1 (mod 7).

4. Multiply each partial product by its congruence term and the modular inverse.
- For the first congruence, we have 1 * 35 * 2 = 70.
- For the second congruence, we have 4 * 21 * 1 = 84.
- For the third congruence, we have 2 * 15 * 1 = 30.

5. Add up the results obtained in the previous step. In this case, 70 + 84 + 30 = 184.

6. Take the result from the previous step and find its remainder when divided by the product of all the moduli (105). In this case, 184 % 105 = 79.

Therefore, the number we are looking for is 79.