Problem. Two piles; a move removes any number from one pile, or the same number from both. Whoever cannot move loses.
Answer: the losing positions are for , : In each pair the difference is .
bool wythoffLosing(long long a, long long b) { // P-position iff smaller = floor(k * phi), k = difference
if (a > b) swap(a, b);
long long k = b - a, s = sqrtl((long double)5 * k * k);
while (s * s > 5 * k * k) s--; while ((s + 1) * (s + 1) <= 5 * k * k) s++;
return a == (k + s) / 2; // floor(k * (1 + sqrt 5) / 2)
}Proof: the losing positions
Define and . These pairs are exactly the P-positions: from , a single-pile move changes one coordinate and yields no pair (each number occurs in exactly one pair), and a diagonal move keeps the difference , which belongs only to pair . From any other position , : if with , move to ; if , move the other pile to ; otherwise with , and the diagonal move to with exists. Finally, , by Beatty’s theorem (, so these sequences partition the positive integers). The code computes with an exact integer square root. Checked against the game DP for piles below 80.