CF679A.Bear and Prime 100

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

这是一个交互式问题。在下方的输出部分中,你将看到有关刷新输出的信息。

熊 Limak 心中想了一个隐藏的数——一个在区间 [2, 100][2, 100] 内的整数。你的任务是判断该隐藏数是质数还是合数。

若整数 x>1x > 1 恰好有两个不同的正因数(即 11 和 xx),则称其为质数;若整数 x>1x > 1 不是质数,则称其为合数。

你可以最多进行 20 次关于隐藏数因数的询问。每次询问时,你应输出一个在区间 [2, 100][2, 100] 内的整数。系统将回答 "yes",当且仅当你输出的整数是隐藏数的一个因数;否则,回答 "no"。

例如,若隐藏数为 1414,则系统仅在你输出 22、77 或 1414 时回答 "yes"。

当你完成所有询问后,请输出 "prime" 或 "composite",然后终止程序。

若你询问次数超过 20 次,或输出了不在区间 [2, 100][2, 100] 内的整数,则会得到 Wrong Answer 判定。此外,若你输出的答案不正确,也会得到 Wrong Answer 判定。

若你未输出任何内容(但你应该输出),或忘记刷新输出(详见下文),则会得到 Idleness Limit Exceeded 判定。

输入格式

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.

每次查询后,您应从输入中读取一个字符串。如果所输出的整数是隐藏数字的约数,则该字符串为 "yes";否则为 "no"。

输出格式

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.

你最多可以进行 20 次查询操作——每次查询需在一行中输出一个区间 [2, 100][2,\,100] 内的整数。输出该整数后,必须同时输出换行符并刷新输出缓冲区。刷新后,你需要从输入中读取响应。

在任意时刻,你都可以输出答案 "prime" 或 "composite"(不带引号)。输出后,请刷新输出缓冲区并终止程序。

刷新输出的方法如下(在输出整数及换行符之后立即调用):

  • C++ 中使用 fflush(stdout);
  • Java 中使用 System.out.flush();
  • Python 中使用 stdout.flush();
  • Pascal 中使用 flush(output);
  • 其他语言请参考相应文档。

Hack(攻击)说明:要对他人提交的程序进行 Hack,你的输入应为一个隐藏数字——即一个位于区间 [2, 100][2,\,100] 内的整数。当然,被 Hack 的程序无法从输入中读取该隐藏数字。

输入输出样例

  • 输入#1

    yes
    no
    yes

    输出#1

    2
    80
    5
    composite
  • 输入#2

    no
    yes
    no
    no
    no

    输出#2

    58
    59
    78
    78
    2
    prime

说明/提示

The hidden number in the first query is 30. In a table below you can see a better form of the provided example of the communication process.

The hidden number is divisible by both 2 and 5. Thus, it must be composite. Note that it isn't necessary to know the exact value of the hidden number. In this test, the hidden number is 30.

59 is a divisor of the hidden number. In the interval [2, 100] there is only one number with this divisor. The hidden number must be 59, which is prime. Note that the answer is known even after the second query and you could print it then and terminate. Though, it isn't forbidden to ask unnecessary queries (unless you exceed the limit of 20 queries).

第一次查询中隐藏的数字是 30。下表以更清晰的形式展示了所提供的交互过程示例。

隐藏的数字同时能被 2 和 5 整除,因此它必定是合数。注意:我们并不需要知道隐藏数字的确切值。在本测试用例中,隐藏数字为 30。

59 是隐藏数字的一个因数。在区间 [2, 100][2,\,100] 中,仅有一个数具有该因数。因此隐藏数字必为 59,而 59 是质数。注意:在第二次查询后答案即已确定,此时你便可输出答案并终止程序。不过,只要未超出最多 20 次查询的限制,进行额外(非必要)的查询也是允许的。

输入解题思路,AI测评打分。不知道怎么写?

首页