Solving Project Euler problem #387 https://projecteuler.net/problem=387