solution to euler 40.