#题解/Game
Game
https://ac.nowcoder.com/acm/contest/19305/1030
思路:这个题目的意思就是,输入一个正整数N,每回合每个人都有一次将其分解为任意两个因数,直到不能分解,不能分解的一方为败者,最后输出这个败者的名字。也就是说我们是在将一个合数分解为两个质数,直到这个数为质数为止。我们可以用temp计录分解的次数,我们来模拟一下样例,在Nancy先手操作时,我们能发现当temp为偶数时Johson为败者,否则Nancy为败者
前置知识
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin>>n;
int temp=0;
for (int i=2;i<=n;i++)
{
while (n%i==0)//如果能被整除那么i就是其质因子
{
temp++;
n=n/i;
}
}
if (temp&1)
{
cout<<"Nancy";
}
else
{
cout<<"Johnson";
}
return 0;
}
查看8道真题和解析