faster version of euler005