博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #356 (Div. 2) C. Bear and Prime 100(转)
阅读量:5323 次
发布时间:2019-06-14

本文共 3213 字,大约阅读时间需要 10 分钟。

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 链接:我发现cf下面的note真的很好,这就让我们清楚的理解了题意,但这题在当时看的时候还是不怎么懂 = = 直到我看了大神(qsc)的题解才有点明白,感觉他说的很好,所以就copy过来了,现在链接发下,因为我们要尊重原创嘛。 链接:

题意

现在在[2,100]里面有一个隐藏的数字,你现在可以问最多20个问题,每个问题可以提出一个数,如果这个数是隐藏的数字的因子的话

那么就会返回yes

否则就会返回no

让你判断这个数是合数,还是素数

题解:

把小于50的素数全部问了一遍,且把4 9 25 49这四个小于100的素数的平方问一遍就好了

如果超过1次回答为yes的话,那么就是合数。

道理很显然,因为一个合数肯定是一个素数乘以另外一个素数,所以至少有2嘛,第二个数就是小于等于50的了

 

我再补充下:就是说[2,100]的所有合数,肯定是①由[2,50]的所以素数两两相乘得到的(15个数),②素数自己乘两次得到的(4个数,4 9 25 49)。只要是那里的合数,肯定满足这两个条件。所以询问这几个数,如果出现2次或以上yes,就是合数,否则是质数。

大神说这是水题,Orz。为什么我觉得还是有些难度呢,- -,肯定是因为我太弱啦~~

#include
using namespace std;vector
ans;void TAT(){ for(int i=2;i<=50;i++) { int flag = 0; for(int j=2;j
>s; if(s=="yes")tmp++; } if(tmp<2)cout<<"prime"<

转载于:https://www.cnblogs.com/s1124yy/p/5576237.html

你可能感兴趣的文章
redis 存储时间区间的数据
查看>>
STM32F0库函数初始化系列:进入STOP模式,外部中断唤醒
查看>>
p1525 关押罪犯
查看>>
使用Html5shiv.js让ie支持html5
查看>>
DBA 优化法则
查看>>
用Python连接SQLServer抓取分析数据、监控 (pymssql)
查看>>
升级ruby后再安装cocodPod
查看>>
MySQL数据库8(十三)高级数据操作之select指令
查看>>
随心测试_Python Se_002<不同浏览器驱动>
查看>>
LeetCode 202. Happy Number
查看>>
【Codeforces Round #432 (Div. 2) A】 Arpa and a research in Mexican wave
查看>>
HTTP协议
查看>>
转载 jenkins执行selenium 测试 浏览器不显示解决方法
查看>>
spring+mybatis利用interceptor(plugin)兑现数据库读写分离
查看>>
wenbao与极角排序
查看>>
回顾JAVA---3.异常
查看>>
data Binding
查看>>
SSM配置
查看>>
HDU 5957 Query on a graph
查看>>
java基础语法
查看>>