787. Bézout's Game

Two players play a game with two piles of stones. They take alternating turns. If there are currently stones in the first pile and stones in the second, a turn consists of removing stones from the first pile and from the second in such a way that . The winner is the player who first empties one of the piles.

Note that the game is only playable if the sizes of the two piles are coprime.

A game state is a winning position if the next player can guarantee a win with optimal play. Define to be the number of winning positions with , , and . Note the order matters, so for example and are distinct positions.

You are given and .

Find .

787. 裴蜀游戏

现有两名玩家,用着两堆石子,玩着一个游戏。二人轮流进行操作。
若此时第一堆里有 枚石子,第二堆里有 枚石子。则某名玩家在操作时,可以从第一堆里拿走 枚石子,从第二堆里拿走 枚石子,且满足:。如果某玩家操作完毕后,取尽了某一堆石子,则该玩家获胜。

不难发现,只有当 互质时,这个游戏才能玩。

若某个状态 满足下一位玩家能在最优操作下保证获胜,则我们称这个状态为必胜态。再记 为满足 的必胜态 的个数。注意,本题考虑顺序问题。比如说, 在计算时,应被认为是两个不同的状态。已知


这个链接 回到源站。

这个链接 回到详细版题目目录。