Codeforces 150A Win or Freeze (博弈 & 数论)

原创 2018年04月17日 15:47:47

A. Win or Freeze
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should run this number of circles around the hotel. Let us remind you that a number's divisor is called non-trivial if it is different from one and from the divided number itself.

The first person who can't make a move wins as he continues to lie in his warm bed under three blankets while the other one keeps running. Determine which player wins considering that both players play optimally. If the first player wins, print any winning first move.

Input

The first line contains the only integer q (1 ≤ q ≤ 1013).

Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cincout streams or the %I64dspecificator.

Output

In the first line print the number of the winning player (1 or 2). If the first player wins then the second line should contain another integer — his first move (if the first player can't even make the first move, print 0). If there are multiple solutions, print any of them.

Examples
input
Copy
6
output
Copy
2
input
Copy
30
output
Copy
1
6
input
Copy
1
output
Copy
1
0
Note

Number 6 has only two non-trivial divisors: 2 and 3. It is impossible to make a move after the numbers 2 and 3 are written, so both of them are winning, thus, number 6 is the losing number. A player can make a move and write number 6 after number 306, as we know, is a losing number. Thus, this move will bring us the victory.

【题目链接】点击有惊喜

【题意】给定一个数n,两个人轮流写出当前数的因子,则当前的数n也就变成了该选手枚举的因子。当某一选手面临的数n为1或者质数的时候,该选手获胜。如果先手获胜,输出1,并且输出先手写下的第一个因子(即给定的n的因子),否则输出2。

【思路】假设两个素数pi,pj,如果n==pi*pj(i可能等于j),则后手胜;否则先手胜。

【代码如下】

#include <bits/stdc++.h>
#define ll long long
using namespace std;

ll n;
vector<ll>vct;

int main(){
    cin >> n;
    ll x = n;
    for(ll i = 2; i*i <= n; i ++){
       while(n%i==0){
            vct.push_back(i); n /= i;
       }
    }
    if(x!=n && n!=1) vct.push_back(n);
    if(vct.size() > 2) cout << "1" << endl << vct[0]*vct[1] << endl;
    else if(vct.size() == 2) cout << "2" << endl;
    else cout << "1" << endl << "0" << endl;
    return 0;
}



版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/i1020/article/details/79975849

01(CodeforcesC水平)CQU新生周末狂欢赛 N - Win or Freeze

N - Win or Freeze Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u ...
  • u012891055
  • u012891055
  • 2014-12-27 16:18:24
  • 477

SDUT1128 Autumn Single contest

CodeForces 140A New Year Table 这道题做过,标准原题。记得当时比赛就卡了没做出来是之后补的, 所以就继续找题看。不知道当时写没写题解, 一块写了吧。题意:...
  • khn64
  • khn64
  • 2017-11-29 15:57:34
  • 67

CodeForces 151C Win or Freeze(简单题)

题目链接 C. Win or Freeze time limit per test 2 seconds memory limit per test 256 meg...
  • madaidao
  • madaidao
  • 2015-05-16 22:26:31
  • 312

解题报告 之 CodeForces150A Win or Freeze

解题报告 之 CodeForces150A Win or Freeze 素数筛 大数分解 判断素数
  • maxichu
  • maxichu
  • 2015-04-19 20:54:27
  • 834

【质因数分解+简单博弈】Win or Freeze CodeForces - 150A

Think: 1知识点:质因数分解+简单博弈 2题意: (1):输入一个数n(n
  • BlessingXRY
  • BlessingXRY
  • 2017-11-30 22:12:48
  • 61

ACM资料(数论,博弈……)

  • 2010年08月02日 22:29
  • 7.76MB
  • 下载

codeforces 455B(博弈+dp)

题目链接:codeforces 455B题目大意:给出n个字符串,进行k次游戏,每次游戏输家下次作为先手,游戏规则为每次放一个字母,导致当前构造的字符串是给定的任意一个字符串的前缀,不能操作时为输,赢...
  • qq_24451605
  • qq_24451605
  • 2015-09-22 10:01:19
  • 1067

CodeForces 150A Win or Freeze(素筛+分情况)

You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the foll...
  • qq_37497322
  • qq_37497322
  • 2017-12-07 22:53:02
  • 112

codeforces 151C Win or Freeze

C. Win or Freeze time limit per test 2 seconds memory limit per test 256 megabytes ...
  • EventQueue
  • EventQueue
  • 2016-08-06 11:12:57
  • 233

取石子(一)-博弈数论

取石子(一) 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述一天,TT在寝室闲着无聊,和同寝的人玩起了取石子游戏,而由于条件有限,他/她们是用旺...
  • qq_18661257
  • qq_18661257
  • 2015-08-03 09:18:27
  • 518
收藏助手
不良信息举报
您举报文章:Codeforces 150A Win or Freeze (博弈 & 数论)
举报原因:
原因补充:

(最多只允许输入30个字)