zoukankan      html  css  js  c++  java
  • codeforces 356 div2 C.Bear and Prime 100 数学

    C. Bear and Prime 100
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    This is an interactive problem. In the output section below you will see the information about flushing the output.

    Bear Limak thinks of some hidden number — an integer from interval [2, 100]. Your task is to say if the hidden number is prime or composite.

    Integer x > 1 is called prime if it has exactly two distinct divisors, 1 and x. If integer x > 1 is not prime, it's called composite.

    You can ask up to 20 queries about divisors of the hidden number. In each query you should print an integer from interval [2, 100]. The system will answer "yes" if your integer is a divisor of the hidden number. Otherwise, the answer will be "no".

    For example, if the hidden number is 14 then the system will answer "yes" only if you print 2, 7 or 14.

    When you are done asking queries, print "prime" or "composite" and terminate your program.

    You will get the Wrong Answer verdict if you ask more than 20 queries, or if you print an integer not from the range [2, 100]. Also, you will get the Wrong Answer verdict if the printed answer isn't correct.

    You will get the Idleness Limit Exceeded verdict if you don't print anything (but you should) or if you forget about flushing the output (more info below).

    Input

    After each query you should read one string from the input. It will be "yes" if the printed integer is a divisor of the hidden number, and "no" otherwise.

    Output

    Up to 20 times you can ask a query — print an integer from interval [2, 100] in one line. You have to both print the end-of-line character and flush the output. After flushing you should read a response from the input.

    In any moment you can print the answer "prime" or "composite" (without the quotes). After that, flush the output and terminate your program.

    To flush you can use (just after printing an integer and end-of-line):

    • fflush(stdout) in C++;
    • System.out.flush() in Java;
    • stdout.flush() in Python;
    • flush(output) in Pascal;
    • See the documentation for other languages.

    Hacking. To hack someone, as the input you should print the hidden number — one integer from the interval [2, 100]. Of course, his/her solution won't be able to read the hidden number from the input.

    Examples
    input
    yes
    no
    yes
    output
    2
    80
    5
    composite
    input
    no
    yes
    no
    no
    no
    output
    58
    59
    78
    78
    2
    prime

    题意:人机交互,回答是否整除,确定那个数;

    思路:就是前14个素数,4个素数的平方

    #include<bits/stdc++.h>
    using namespace std;
    #define ll __int64
    #define mod 1000000007
    #define pi (4*atan(1.0))
    const int N=1e2+10,M=1e6+10,inf=1e9+10;
    int p[30]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
    int aa[10]={4,9,25,49};
    char a[N][30];
    int main()
    {
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        int x,y=0,n=0,z,i,t=0;
        for(i=0;i<15;i++)
        {
            printf("%d
    ",p[i]);
            fflush(stdout);
            scanf("%s",a[i]);
            if(a[i][0]=='y')
            y++;
            else
            n++;
            if(y>=2)
            break;
        }
        for(i=0;i<4;i++)
        {
            printf("%d
    ",aa[i]);
            fflush(stdout);
            scanf("%s",a[i]);
            if(a[i][0]=='y')
            y++;
            else
            n++;
            if(y>=2)
            break;
        }
        if(y>=2)
            {
                printf("composite
    ");
                fflush(stdout);
            }
            else
            {
                printf("prime
    ");
                fflush(stdout);
            }
        return 0;
    }
  • 相关阅读:
    div常用设置
    Chrome-Charset——Chrome最新版右键工具中的编码修改功能没有了的解决工具
    PHP数据访问(面向对象方式:mysqli类)
    JSON
    jQuery
    jQuery事件
    会话保持
    查询的例子,房屋租赁
    PHP CRUD
    批量删除
  • 原文地址:https://www.cnblogs.com/jhz033/p/5571880.html
Copyright © 2011-2022 走看看