• codeforce150A(简单的求质数问题)


    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 cin, cout 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
    2
    input
    Copy
    30
    output
    1
    6
    input
    Copy
    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.

    只要找到p除1和本身外的两个质因素1就一定赢

    #include<stdio.h>
    #include<math.h>
    int check(__int64 n)
    {
    __int64 i,k;
    for(i=2;i<=sqrt(n);i++)
    {
    if(n%i==0)
    return 0;
    }
    return 1;
    }
    int main()
    {
    __int64 q;
    __int64 i,sum,k;
    scanf("%I64d",&q);
    sum=1;
    k=1;
    for(i=2;i<=sqrt(q);i++)
    {
    if(q%i==0&&check(i))
    {
    //printf("W%d ",i);
    sum++;
    if(i*i<q&&q%(i*i)==0)//注意当i的平方也是q的因数时i可以当两个质数用
    {
    printf("1 %I64d ",i*i);
    return 0;
    }
    k*=i;
    if(sum>=3)
    {
    printf("1 %I64d ",k);
    return 0;
    }
    }
    }
    if(sum==1)
    printf("1 0 ");
    else
    printf("2 ");
    return 0;

    }

  • 相关阅读:
    百度大脑IOCR财会票据识别技术接入小程序,快速实现财会票据识别
    接入百度大脑一站式内容审核平台,可快速提升审核效率
    利用百度AI快速开发出一款“问答机器人”并接入小程序
    接入百度大脑表格文字识别技术,快速降低信息电子化录入成本
    百度大脑UNIT3.0智能对话技术全面解析
    利用百度大脑,快速搭建一个红酒识别的小程序
    百度大脑UNIT3.0详解之嵌入式对话理解技术
    人群流量监控,安全管理升级
    python globals函数
    python reduce/map/filter函数区别
  • 原文地址:https://www.cnblogs.com/cglongge/p/8540526.html
Copyright © 2020-2023  润新知