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;
}