#P2953. [USACO09OPEN] Cow Digit Game S
[USACO09OPEN] Cow Digit Game S
Description
Bessie is playing a number game against Farmer John, and she wants you to help her win.
Game starts with an integer (). Bessie goes first, and then the two players alternate turns. On each turn, a player can subtract from the current number either its largest digit or its smallest nonzero digit to obtain a new number. For example, from we may subtract either or to obtain either or , respectively. The game continues until the number becomes , at which point the last player to have taken a turn is the winner.
Bessie and FJ play () games. Determine, for each game, whether Bessie or FJ will win, assuming both play optimally (that is, on each turn, if the current player has a move that guarantees a win, they will take it).
Consider a sample game where . Bessie goes first and takes , leaving . FJ is forced to take , leaving . Bessie takes the remainder and wins the game.
Input Format
- Line 1: A single integer .
- Lines 2..: Line contains the single integer .
Output Format
- Lines 1..: Line contains 'YES' if Bessie can win game , and 'NO' otherwise.
2
9
10
YES
NO
Hint
For the first game, Bessie simply takes the number and wins. For the second game, Bessie must take (since she cannot take ), and then FJ can win by taking .
Translated by ChatGPT 5
京公网安备 11011102002149号