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
x^3 = 1 mod(2)
x^3 = 1 mod(3)
...
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:
N = 91 = 7*13, we must solve
x^3 = 1 mod(7)
There are 3 solutions: 1, 2, 4
x^3 = 1 mod(13)
There are 3 solutions: 1, 3, 9
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
CRF(1, 1, 7, 13) = 1
CRF(1, 3, 7, 13) = 29
CRF(1, 9, 7, 13) = 22
CRF(2, 1, 7, 13) = 79
CRF(2, 3, 7, 13) = 9
CRF(2, 9, 7, 13) = 16
CRF(4, 1, 7, 13) = 53
CRF(4, 3, 7, 13) = 81
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)