1755 除数游戏
- 1.0 秒
- 131,072.0 KB
- 20 分
- 3级题
在除数游戏中,两人轮流行动,初始时有一个整数q,每次行动要写下一个整数,这个整数必须是最近一次出现的整数的“强除数”。所谓一个整数的“强除数”是指除了1和该整数本身以外,可以整除该整数的整数。
当游戏的某一方找不出符合以上条件的整数时,该方取得胜利,游戏结束。
假设游戏双方都采取最好的策略,给出初始数字。计算第一个写数字的人赢,还是第二个写数字的人赢。
样例解释:
在样例一中,数字6的“强除数”是2和3。不管是写哪个数字,下一个人都赢了。
在样例二中,6是30的一个“强除数”。写下6后,接下来的过程同上。
收起
输入
单组测试数据。 第一行,有1个整数q(1≤q≤10^13) 表示初始数字。
输出
共一行,如果第一个写数字的人赢,则输出1,否则输出2。
输入样例
样例一 6 样例二 30
输出样例
输出一 2 输出二 1
输出1的情况是为素数、或者是1、或者是a1,a2...个数>2。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=10000+66;
const ll mod=1e9+7;
ll n;
bool check(ll x)
{
if(x==1)return false;
if(x==2)return true;
for(ll i=2;i<=sqrt(n);i++)
{
if(x%i==0)return false;
}
return true;
}
int get_num(int n){
int tot=1;
int x1=0;
for(int i=2;i*i<=n;++i){
if(n%i==0){
int x=0;
while(n%i==0){
n/=i;
x++;
x1++;
}
tot*=(x+1);
}
}
if(n>1)tot*=2,x1++;
cout<<x1<<"+"<<endl;
return tot;
}
bool get_num(ll n){
int tot=0;
for(ll i=2;i*i<=n;++i){
while(n%i==0){
n/=i;
tot++;
}
}
if(n>1)tot++;//---
//cout<<tot<<"----"<<endl;
return tot>2;
}
int main()
{
//cout<<get_num(4)<<"--"<<endl;
scanf("%lld",&n);
if(check(n)||get_num(n)||n==1)
{
printf("%d\n",1);
}
else
{
printf("%d\n",2);
}
return 0;
}