C - Win or Freeze
1.思路
題目給定一個(gè)數(shù),兩個(gè)人輪流操作:把這個(gè)數(shù)換成他的非平凡因數(shù),如果有個(gè)人不能操作了,那么這個(gè)人就贏了。輸出第幾個(gè)人勝利,如果第一個(gè)人勝利,則還要輸出它的第一次操作。如果我制造出一個(gè)只有兩個(gè)質(zhì)數(shù)的數(shù),這樣對手只能取走其中一個(gè),然后我走不動(dòng)了,我就贏了,特判n為1。
2.代碼
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 const int maxn = 2e5 + 5; 5 ll n; 6 ll a[maxn]; 7 int cnt; 8 bool judge(ll x) { 9 for(ll i = 2; i * i <= x; i++) { 10 if(x % i == 0) { 11 return false; 12 } 13 } 14 return true; 15 } 16 void fenjie(ll x) { 17 for(ll i = 2; i * i <= x; i++) { 18 if(x % i == 0 && judge(i)) { 19 while(x % i == 0) { 20 a[++cnt] = i; 21 x /= i; 22 } 23 } 24 if(cnt >= 2) { 25 break; 26 } 27 } 28 if(x > 1) { 29 a[++cnt] = x; 30 } 31 } 32 int main() { 33 cin >> n; 34 if(n == 1 || judge(n)) { 35 cout << 1 << endl << 0 << endl; 36 return 0 ; 37 } 38 fenjie(n); 39 if(cnt == 2 && a[1]*a[2] == n) { 40 cout << 2 << endl; 41 } else { 42 cout << 1 << endl; 43 printf("%lld\n", a[1] * a[2]); 44 } 45 46 return 0 ; 47 }
浙公網(wǎng)安備 33010602011771號