Project Euler 271 - Modular Cubes, part 1

Official link: https://projecteuler.net/problem=271

Thought Process

First thing to notice is that 13082761331670030 = 2*3*5*...*43

This means that solving for x^3 = 1 mod(13082761331670030) is equivalent to solving the following system of equations by the Chinese Remainder Theorem

  1. x^3 = 1 mod(2)

  2. x^3 = 1 mod(3)

  3. ...

  4. x^3 = 1 mod(43)

So first I need to write a Chinese Remainder Function (CRF), which is now included in my Essential functions page!

Then we find the solutions for all of these and continuously build solutions, for example:

  1. N = 91 = 7*13, we must solve

  2. x^3 = 1 mod(7)

    1. There are 3 solutions: 1, 2, 4

  3. x^3 = 1 mod(13)

    1. There are 3 solutions: 1, 3, 9

  4. Now I build my solutions with CRF, which takes 4 inputs a1, a2, n1, n2 where x = a1 mod n1, x = a2 mod n2, and finds the unique solutions

  5. CRF(1, 1, 7, 13) = 1

  6. CRF(1, 3, 7, 13) = 29

  7. CRF(1, 9, 7, 13) = 22

  8. CRF(2, 1, 7, 13) = 79

  9. CRF(2, 3, 7, 13) = 9

  10. CRF(2, 9, 7, 13) = 16

  11. CRF(4, 1, 7, 13) = 53

  12. CRF(4, 3, 7, 13) = 81

  13. CRF(4, 9, 7, 13) = 74

This gives us all the solutions!

Interactive Code

Enter a number, yourinput, from the following list [2*3 = 6, 2*3*5 = 30, 2*3*5*7 = 210, 2*3*5*7*11 = 330, ...]

Code will output S(yourinput)