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

17 篇文章 0 订阅

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.

Example
Input
6
Output
2
Input
30
Output
1
6
Input
1
Output
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 6is 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.


题解:

找规律不难发现当一个数可以分成2个以上的素数的时候1可以获胜,否则2获胜,1获胜时只要输出2个素数的乘积就好了

重点是这题数据范围特别大,打表只能达到4*1e6的样子,然后还要分一波情况。。这题好坑wa了好几发,原因是特别大的素数要特判

代码:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<stdlib.h>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#include<stdio.h>
using namespace std;
#define ll long long
ll p[283150];
int vis[4000005];
int ans;
void init()
{
    int i,j;
    memset(vis,0,sizeof(vis));
    for(i=2;i<=4000001;i++)
    {
        if(vis[i])
           continue;
        p[ans]=i;
        ans++;
        for(j=i*2;j<=4000001;j+=i)
            vis[j]=1;
    }
}
int main()
{
    ll n,add=0,t=1,i;
    ans=0;
    init();
    scanf("%lld",&n);
    ll temp=n;
    for(i=0;i<ans&&p[i]<=n;i++)
    {
        if(n%p[i]==0)
        {
            while(n%p[i]==0)
            {
                n/=p[i];
                add++;
                if(add>2)
                    break;
                t*=p[i];
            }
            if(add>2)
                break;
        }
    }
    if(temp==1||(add==1&&n==1)||add==0)
    {
        printf("1\n0\n");
        return 0;
    }
    if(add>2||add==2&&n!=1)
    {
        printf("1\n%lld\n",t);
    }
    else
        printf("2\n");
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值