Codeforces 151C(分解因数)

来源:互联网 发布:多可网络爬虫 编辑:程序博客网 时间:2024/05/22 15:29

问题描述:

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-trivialdivisor 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.

input

6

output

2

题目题意:题目给了我们一个数,然后让俩个人对数操作即:可以把这个数换成他的因数(但是不能是1和它本身),如果那个人不能操作了,那么他就胜利。第一个人胜利,则输出它的第一场操作

题目分析:仔细想一下不能发现,其实第一个人胜利的机会很大,只要它第一个数换的好的话!我们假设第一个人把数换成原数的最小俩个因子的积,那么肯定就是他赢了,如果没有的话,那么肯定2赢了。

代码如下:

#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#define ll long longusing namespace std;ll factor[100],fcnt;bool check(ll n){    for (int i=2;i<=(int) sqrt(n);i++) {        if (n%i==0) return false;    }    return true;}int main(){    ll n,m;    while (cin>>n) {        fcnt=0;        m=n;        if (n==1||check(n)) {//质数也是他赢            printf("%d\n%d\n",1,0);            continue;        }        for (int i=2;i<=(int)sqrt(n);i++) {            if (n%i==0) {                while (n%i==0) {                    factor[fcnt++]=i;                    n=n/i;                    if (fcnt>=2) break;                }            }            if (fcnt>=2) break;        }      //  cout<<factor[0]<<" "<<factor[1]<<endl;        if (fcnt>=2&&factor[0]*factor[1]!=m) {//还要避免是它本身            printf("1\n");            printf("%lld\n",factor[0]*factor[1]);        }        else {            printf("%d\n",2);        }    }    return 0;}