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

题意

现在在[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<bits/stdc++.h>
using namespace std;
vector<int> ans; void TAT()
{
for(int i=;i<=;i++)
{
int flag = ;
for(int j=;j<i;j++)
if(i%j==)flag = ;
if(flag==)ans.push_back(i);
}
ans.push_back();
ans.push_back();
ans.push_back();
ans.push_back();
int tmp = ;
for(int i=;i<ans.size();i++)
{
cout<<ans[i]<<endl;
string s;
cin>>s;
if(s=="yes")tmp++;
}
if(tmp<)cout<<"prime"<<endl;
else cout<<"composite"<<endl;
}
int main()
{
TAT();
return ;
}

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 题目连接: http://www.codeforces.com/contest/680/problem/C Description This is an i ...

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

  3. Codeforces Round #356 (Div. 2)A. Bear and Five Cards(简单模拟)

    A. Bear and Five Cards time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  4. Codeforces Round #356 (Div. 1) D. Bear and Chase 暴力

    D. Bear and Chase 题目连接: http://codeforces.com/contest/679/problem/D Description Bearland has n citie ...

  5. Codeforces Round #356 (Div. 2) E. Bear and Square Grid 滑块

    E. Bear and Square Grid 题目连接: http://www.codeforces.com/contest/680/problem/E Description You have a ...

  6. Codeforces Round #356 (Div. 2) D. Bear and Tower of Cubes dfs

    D. Bear and Tower of Cubes 题目连接: http://www.codeforces.com/contest/680/problem/D Description Limak i ...

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

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

  9. Codeforces Round #356 (Div. 1) C. Bear and Square Grid

    C. Bear and Square Grid time limit per test 3 seconds memory limit per test 256 megabytes input stan ...

随机推荐

  1. Linux网络管理概述

    概述:计算机基础知识.网络基础知识其实是所有的程序员所必须的,甚至已经不仅仅是程序员的专利,而是每一个人都应该掌握的计算机知识. 主要内容: 一.网络基础 二.Linux网络配置 三.Linux网络命 ...

  2. 关于MSP430中断机制

    中断很大程度上体现了一款单片机的性能,从这一点将MSP430在中断方面做得很不错,主要是提供了非常丰富的中断源,基本的有IO中断,定时器中断和一些接口中断(SPI,UART,I2C)等等.     现 ...

  3. Fortran编译多个文件(转载)

    最近需要在Linux系统下编译多个Fortran程序,在网上搜索了一下,但是资料不多,也许因为这个问题比较简单,不值一提,但还是把我知道的写出来,供大家参考: 方法一: 假如现在有两个Fortran程 ...

  4. 关于jquery easyui treegrid的问题

    我是用的django web开发架构: 想实现如下功能: 权限架构 点击checkbox时,能获取该checkbox的值: 代码如下: <tr> <th field="na ...

  5. PHP 堆排序实现

    在<算法: C语言实现>上看到的写法,很简洁,用PHP实现一把. <?php /* fixDown实现对某一个节点的向下调整,这里默认的是起始节点为1,方便计算父子节点关系 注: 起 ...

  6. 怎么用ABBYY打开PDF文档

    我们日常工作中接触的文档大多都是PDF格式的,这种格式的文件需要借助工具才能打开,大家最熟悉的无非就是Adobe了,但你知道吗?除了Adobe,OCR文字识别软件也可以打开PDF文档,比如ABBYY ...

  7. linux概念之内存分析

    linux内存总结 分析样本[root@-comecs ~]# free total used free shared buffers cached Mem: -/+ buffers/cache: S ...

  8. ASP.NET 将数据生成PDF (二)

    可以下载itextsharp(https://sourceforge.net/projects/itextsharp)下载,然后在工程中引用该控件,举例子如下 1  datatable 的内容转换为P ...

  9. eclipse安装完成后配置tomcat server runtime evironment

    安装eclipse后创建web项目需要运行在tomcat服务器上,这里是tomcat的配置:(前提是电脑上已经安装了tomcat!)

  10. HBase(一): c#访问hbase组件开发

    HDP2.4安装系列介绍了通过ambari创建hbase集群的过程,但工作中一直采用.net的技术路线,如何去访问基于Java搞的Hbase呢? Hbase提供基于Java的本地API访问,同时扩展了 ...