mathematical code inspired by projecteuler.net