Faster version of problem 92