Solving some maths with Java wizardry. Thanks to projecteuler.net for the challenge!