有一堆石子共有N个。A B两个人轮流拿,A先拿。每次拿的数量只能是2的正整数次幂,比如(1,2,4,8,16….),拿到最后1颗石子的人获胜。假设A B都非常聪明,拿石子的过程中不会出现失误。给出N,问最后谁能赢得比赛。
例如N = 3。A只能拿1颗或2颗,所以B可以拿到最后1颗石子。(输入的N可能为大数)
这是个博弈题。。我们可以先打个表看看
打表的过程如下
#include #include #include #include #include
打完表我们可以知道B赢得情况是只有n能被3整除的时候。然后就很好做辣
#include #include #include #include #include