2018 Multi-University Training Contest 2 D(Game)

Problem Description
Alice and Bob are playing a game.
The game is played on a set of positive integers from 1 to n.
In one step, the player can choose a positive integer from the set, and erase all of its divisors from the set. If a divisor doesn't exist it will be ignored.
Alice and Bob choose in turn, the one who cannot choose (current set is empty) loses.
Alice goes first, she wanna know whether she can win. Please judge by outputing 'Yes' or 'No'.
 

Input
There might be multiple test cases, no more than 10. You need to read till the end of input.
For each test case, a line containing an integer n. (1≤n≤500)
 

Output
A line for each test case, 'Yes' or 'No'.
 

Sample Input
1
 

Sample Output
Yes

题意:A和B两人博弈,A先开始,每次在 1~n 中取一个数 i,消除 i 的因子(包括 1 和它自己本身),谁先消除完谁胜利。输入 n,问 A 可以胜利吗?

思路:将1到n分为1和2-n两部分,讨论。

1,当2-n之间,先手必胜,那么A取必胜点,必然1也是其因子被取出,剩下B必败。

2,当2-n之间,先手必败,那么A可以先取1,留给B必败。

所以就输出"Yes"就可以了。

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        printf("%Yes\n");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/snayf/article/details/81227695