zoukankan      html  css  js  c++  java
  • codeforces 150A 质数因子

    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 cin, cout 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 6 is the losing number. A player can make a move and write number 6 after number 30; 6, as we know, is a losing number. Thus, this move will bring us the victory.

    题解:

         如果一个数 n=p^2 或者n=p1*p2 (p,p1,p2为质数)肯定是第二个人获胜,其他情况都是第一人胜利

    代码:

    #include<iostream>
    #include<string.h>
    using namespace std;
    long long a[100000];
    int main()
    {
        long long n;
        while(cin>>n)
        {
            long long sum=0,x=n;
            for(long long i=2;i*i<=n;i++) //储存质数因子;
            {
                while(n%i==0)
                {
                    a[++sum]=i;
                    n/=i;
                }
        }
        if(x!=n&&n!=1) a[++sum]=n;
        if(sum!=2) cout<<"1"<<"
    "<<a[1]*a[2]<<endl;//有两个以上质数因子,或没有1胜,并随意输出两个质数因子的积;
        else cout<<"2"<<endl;//只有两个质数因子则2胜;
        }    
        return 0;
    }
  • 相关阅读:
    感觉博客又要停一停了
    dockManager 添加DockPanel控件
    C# 线性渐变圆
    【Axure】母版引发事件
    【系统问题】windows10打印就蓝屏-报错误代码“win32kfull.sys”
    论扇形的绘制方式
    字符串可以使用substring等方法的原因解析
    深入理解作用域链
    实现fn(1,2)(3)(4).getSum(),使得最后输出值为实参的和即10
    函数里面for循环延迟打印引发的闭包问题
  • 原文地址:https://www.cnblogs.com/xiongtao/p/8543938.html
Copyright © 2011-2022 走看看