Assume the current b>a.
First, B%a==0 win
Second, b<2*a, at present, we have no choice, if the next step is to win (finally to the situation one), the current will be defeated, on the contrary, the current victory.
Third, b>2*a, assuming X is the integer that makes the b-ax<a, consider subtracting a (x-1) from B, for example, minus 12 for (4,19).
At this point, the next state becomes the former said there is no choice of circumstances two, if the state is a must, the current state is the winning state.
If the status is a win state, the next step is the only certainty, so it is a must, so we can directly reach this state.
∴ situation Three is the winning state.
∴ first reached the situation one or three is to win.
#include <cstdio> #include <algorithm>using namespace Std;long long A,b;int main () {while (1) { scanf ("%lld%lld", &a,&b); if (!a&&!b) break; BOOL Flag=1;while (1) { if (a>b) swap (A, b); if (b%a==0| | B> (a<<1)) { puts (flag?) Stan wins ":" Ollie wins "); break; } B-=a; flag^=1; } } return 0;}
"Game theory" poj2348 Euclid ' s game