Codeforces Round #356 (Div. 2) C. Bear and Prime 100 水题
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 水题的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)
Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...
- 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 ...
- 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 ...
- 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/ ...
- 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 ...
- 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 ...
随机推荐
- oracle 创建表空间 、用户 、赋权、建表
一.创建表空间 1.创建临时表空间 create temporary tablespace TS_TEM_TAB_SPACE tempfile 'D:\oracle\TS_TEM_TAB_SPACE. ...
- Memcache 内存分配策略和性能(使用)状态检查【转】
前言: 一直在使用Memcache,但是对其内部的问题,如它内存是怎么样被使用的,使用一段时间后想看看一些状态怎么样?一直都不清楚,查了又忘记,现在整理出该篇文章,方便自己查阅.本文不涉及安装.操作. ...
- 如何扎实自己的Java基础?
问:如何扎实自己的Java基础? 答:玩好JDK JDK其实就是Java SE Development Kit的缩写,要玩好这东西可不简单.JDK主要包含了三部分,第一部分就是Java运行时环境,这其 ...
- 【C语言学习笔记】字符串拼接的3种方法 .
昨天晚上和@buptpatriot讨论函数返回指针(malloc生成的)的问题,提到字符串拼接,做个总结. #include<stdio.h> #include<stdlib.h&g ...
- centos7 部署 seafile
=============================================== 2018/5/13_第1次修改 ccb_warlock == ...
- Nginx实现代理和用户验证
1.下载Nginx 首先去官网http://nginx.org/en/download.html下载需要的版本即可,无需安装,只需要打开nginx.exe文件,nginx.exe的服务就开启了.打开h ...
- poj1976
dp #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ...
- 记录一下mariadb设置主从同步的过程[虚拟机测试]
背景:因为工作的关系,需要找寻实时同步数据到另外系统的服务器的数据库上,查询下来,用mariadb进行跨服务器的同步数据动作,用主从同步比较多,也比较保险 也有使用shell脚本的,定时定候的执行my ...
- idea心得
概述 Intellij IDEA真是越用越觉得它强大,它总是在我们写代码的时候,不时给我们来个小惊喜.出于对Intellij IDEA的喜爱,我决定写一个与其相关的专栏或者系列,把一些好用的Intel ...
- luoguP2735 电网 Electric Fences
一道校内模拟赛遇见的题 ** 不会正解就真的很麻烦的 数学题 ** 有一种东西叫 皮克定理 发现的千古神犇: 姓名:George Alexander Pick(所以叫皮克定理呀 国籍:奥地利(蛤!竟然 ...