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;
}

Codeforces Round #356 (Div. 2) C. Bear and Prime 100 水题的更多相关文章

  1. Codeforces Round #356 (Div. 2) C. Bear and Prime 100(转)

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

  2. Codeforces Round #356 (Div. 2) B. Bear and Finding Criminal 水题

    B. Bear and Finding Criminals 题目连接: http://www.codeforces.com/contest/680/problem/B Description Ther ...

  3. Codeforces Round #356 (Div. 2) A. Bear and Five Cards 水题

    A. Bear and Five Cards 题目连接: http://www.codeforces.com/contest/680/problem/A Description A little be ...

  4. Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)

    Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...

  5. Codeforces Round #356 (Div. 2)B. Bear and Finding Criminals(水题)

    B. Bear and Finding Criminals time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  6. Codeforces Round #373 (Div. 2) C. Efim and Strange Grade 水题

    C. Efim and Strange Grade 题目连接: http://codeforces.com/contest/719/problem/C Description Efim just re ...

  7. Codeforces Round #185 (Div. 2) A. Whose sentence is it? 水题

    A. Whose sentence is it? Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...

  8. Codeforces Round #373 (Div. 2) A. Vitya in the Countryside 水题

    A. Vitya in the Countryside 题目连接: http://codeforces.com/contest/719/problem/A Description Every summ ...

  9. Codeforces Round #371 (Div. 2) A. Meeting of Old Friends 水题

    A. Meeting of Old Friends 题目连接: http://codeforces.com/contest/714/problem/A Description Today an out ...

随机推荐

  1. MySQL 5.7以后怎么查看索引使用情况?

    MySQL 5.7以后怎么查看索引使用情况? 0.在sys库中查看没用的索引 root@localhost [sys]>select * from schema_unused_indexes; ...

  2. thinkphp模版常量替换机制

  3. Centos之命令搜索命令whereis与which

    Centos之命令搜索命令whereis与which whereis 命令名 #搜索命令所在路径及帮助文档所在位置 选项: -b :只查找可执行文件位置 -m:只查找帮助文件 [root@localh ...

  4. 入门ROS教程与视频汇总(kinetic)

    参考网址: Richard Wang    3 Shawn Chen 部分视频网址: http://v.youku.com/v_show/id_XMjUxMTc5MzE5Mg http://i.you ...

  5. yum安装Mysql-5.6

    MySQL yum库提供了一个简单的和方便的方法来安装和更新MySQL相关的软件包到最新版本. MySQL yum库文档说明:http://dev.mysql.com/doc/mysql-yum-re ...

  6. SQL2000数据库修改sa密码

    开始——程序——Microsoft SQL Server——企业管理器 2 展开数据库Microsoft SQL Server—— SQL Server组——安全性——登录——双击sa 3 在常规内有 ...

  7. CVE-2011-0104 Microsoft Office Excel缓冲区溢出漏洞 分析

    漏洞简述   Microsoft Excel是Microsoft Office组件之一,是流行的电子表格处理软件.        Microsoft Excel中存在缓冲区溢出漏洞,远程攻击者可利用此 ...

  8. Java第三阶段学习(三、字符流、转换流)

    一.字节流读取中文时出现的问题: 文件中有中文时,用字节流读取会出现乱码的问题,因为一个中文为两个字节. 二.字符编码表 编码表:其实就是生活中字符和计算机二进制的对应关系表. 1.ascii: 一个 ...

  9. 1926: [Sdoi2010]粟粟的书架

    大概就是分情况乱搞.. 经典维护二维前缀和暴力+莫队算法 垫底QAQ #include <bits/stdc++.h> using namespace std; namespace my_ ...

  10. 【Java】 Scanner类的几个方法

    通过 Scanner 类可以获取用户的输入,创建 Scanner 对象的基本语法如下: Scanner sc = new Scanner(System.in); nextInt().next()和ne ...