Sunday, August 4, 2013

project euler problem 271

Modular Cubes, part 1

This problem is simple. But pure brute force is not an option.  I checked my old code, I kept a list of "possible solutions" and used something like bigInteger to do the modulo work since the numbers are too big.  It only takes 17 ms, not too bad!

This time, I tried to avoid using bigIntegers since most of the problems with a number greater than 150 may be solved without the help of GMP.  I found there is a better solution which used the famous Chinese Remainder Theorem.  The problem is extremely simple after one understand what is going on inside CRT.  Quite a few other project euler problems also check one's understanding of CRT, this one being the simplest one. It is a good opportunity to learn CRT!
My code runs less than 10 ms.

No comments:

Post a Comment