UVa 10368 - Euclid's Game

10368 - Euclid's Game
http://acm.uva.es/p/v103/10368.html

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