C. Bear and Prime 100

题目连接:

http://www.codeforces.com/contest/680/problem/C

Description

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.

Sample Input

yes

no

yes

Sample Output

2

80

5

composite

Hint

题意

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

那么就会返回yes

否则就会返回no

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

题解:

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

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

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

代码

#include<bits/stdc++.h>
using namespace std;
vector<int> ans; void TAT()
{
for(int i=2;i<=50;i++)
{
int flag = 0;
for(int j=2;j<i;j++)
if(i%j==0)flag = 1;
if(flag==0)ans.push_back(i);
}
ans.push_back(4);
ans.push_back(9);
ans.push_back(25);
ans.push_back(49);
int tmp = 0;
for(int i=0;i<ans.size();i++)
{
cout<<ans[i]<<endl;
string s;
cin>>s;
if(s=="yes")tmp++;
}
if(tmp<2)cout<<"prime"<<endl;
else cout<<"composite"<<endl;
}
int main()
{
TAT();
return 0;
}

最新文章

  1. webpack入门教程之初识loader(二)
  2. [linux]重拾linux
  3. 转:在浏览器地址栏按回车、F5、Ctrl+F5刷新网页的区别
  4. 据说是百度ios面试题
  5. Android NDK引用预编译的动态链接库
  6. 2016多校联合训练contest4 1012Bubble Sort
  7. pyQt事件处理
  8. 自学Xpath的几个例子
  9. SimpleDateFormat使用具体解释
  10. (Nginx学习一)安装和启动及对应文件夹介绍
  11. CentOS的KVM实践(虚拟机创建、网桥配置、Spice)
  12. parted
  13. Bootstrap &amp; 响应式
  14. cookie笔记(一)
  15. animate动画效果
  16. 【MVP时间】5节课助你破解物联网硬件接入难点
  17. matplotlib 刻度,坐标轴不可见
  18. 【git】gitignore
  19. 浅析libuv源码-获取精确时间
  20. 用两条命令看出你买的H3C光模块是否是正品

热门文章

  1. Python Challenge 第 4 关攻略:linkedlist
  2. [shell]shell中if语句的使用
  3. iframe框架加载完成后执行函数
  4. java 局部内部类
  5. python 图片上传写入磁盘功能
  6. MySQL学习笔记:从一个表update到另外一个表
  7. MySQL学习笔记:insert into select
  8. java解析Xml格式的字符串
  9. Ubuntu 使用命令更新 Ubuntu 系统
  10. CCF CSP 201512-3 画图