Processing math: 100%

Project Euler 043

Sub-string divisibility

First, try with all multiples of 17 that has different digits:

¯cbamod17

Since a, b and c are known values, the next step is:

¯dcbmod13

to calculate the value of d:

100d+10c+b0mod13d(10c+b)inv(100,13)mod13

More generally:

100z+10y+x0modpz(10y+x)inv(100,p)modp

Since x and y are known values, (10y+x)%p is also known. To calculate inv(100,p) is enough with a preprocessing for every prime number from 2 to 17. Finally, the equation is similar to: zkmodp, so for every digit the search space is reduced for just 1 or 2 values.

Time Complexity: O(20×10×10)

Just for 2 and 5 is needed to iterate from 0 to 9 and there are just 20 numbers that met the requirements for 17.

Share: X (Twitter) Facebook LinkedIn