improve solution to problem 50000001