UVa 10368 - Euclid's Game

Gotchas
The input number may be greater than 2^31.