https://projecteuler.net/problem=161 The right answer can be found here: http://oeis.org/A215826