Euclid is a two-player impartial game invented by A.J. Cole and A.J.T. Davie in 1969.

A position in Euclid is a pair (x, y) of positive integers. A legal move consists of subtracting from the larger integer any positive multiple of the smaller one, as long as the result is still positive. The game ends when no more moves are possible, namely, at position (d, d), where d = gcd(x, y). The last player to move wins.

The Sprague-Grundy function of Euclid is given by the formula g(x, y) = floor(|y/x - x/y|).


G. Nivasch, "The Sprague-Grundy function of the game Euclid", Discrete Mathematics 306, pp. 2798–2800, 2006.