Codeforces Round #107 (Div. 1) A (数论)

来源:互联网 发布:linux发行版排行榜 编辑:程序博客网 时间:2024/06/17 17:39

题目:

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%I64d specificator.

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.

Sample test(s)
input
6
output
2
input
30
output
16
input
1
output
10
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.

题意分析:

两个人玩一个游戏。初始一个数字q,双方轮流把改数更换为平凡因子,平凡因子的定义就是除了本身和1之外的约数。考虑双方使用的都是最优策略,所以第二玩家只有约数个数为2的时候才能赢。这道题主要是计算一个数的约数个数。

代码:

#include <iostream>#include <stdio.h>#include <vector>using namespace std;vector<long long>ans;int main(){    long long q;    while(cin >> q)    {        ans.clear();        for(long long i=2; i*i<=q; i++)        {            while(q%i==0)            {                ans.push_back(i);                q/=i;            }        }        if(q>1)            ans.push_back(q);        if(ans.size()<2)        {            cout << "1" <<endl;            cout << "0" <<endl;        }        else if(ans.size()==2)        {            cout << "2" <<endl;        }        else        {            cout << "1" <<endl;            cout << ans[0]*ans[1] <<endl;        }    }    return 0;}


0 0
原创粉丝点击