My first instinct was just to simulate it and slap a visited-states check on top.
Model the process as a state transition on the pair (a, b) and identify an invariant that determines termination. Use the binary representation of the ratio a/b to derive a logarithmic-time condition, likely involving the continued fraction expansion or the Euclidean algorithm.
Pro tip: Connect the problem to the Euclidean algorithm: the number of moves until termination is related to the sum of partial quotients in the continued fraction of a/b. This shows logarithmic time because the Euclidean algorithm runs in O(log min(a,b)).
Clarify that each move doubles the smaller pile and subtracts that amount from the larger. The process stops when one pile becomes zero; otherwise it may cycle.
Observe that the total number of stones is invariant. Also, the ratio of the two piles changes in a predictable way: if a < b, the new pair is (2a, b-a).
Show that the sequence of moves mimics the subtractive Euclidean algorithm on the pair (a, b). The number of moves until termination equals the sum of the quotients in the continued fraction of a/b.
Use the fact that the Euclidean algorithm runs in O(log min(a,b)) steps. Therefore, we can simulate the process efficiently by jumping multiple moves at once using division.
Write a function that repeatedly applies the transformation using modulo arithmetic to skip redundant steps, and check if it terminates. Test with small examples to confirm correctness.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.