codeforces 356 div2 C.Bear and Prime 100 数学
1 second
256 megabytes
standard input
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).
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.
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.
yes
no
yes
2
80
5
composite
no
yes
no
no
no
58
59
78
78
2
prime
题意:人机交互,回答是否整除,确定那个数;
思路:就是前14个素数,4个素数的平方
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define mod 1000000007
#define pi (4*atan(1.0))
const int N=1e2+,M=1e6+,inf=1e9+;
int p[]={,,,,,,,,,,,,,,,,,,,,,,,,};
int aa[]={,,,};
char a[N][];
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int x,y=,n=,z,i,t=;
for(i=;i<;i++)
{
printf("%d\n",p[i]);
fflush(stdout);
scanf("%s",a[i]);
if(a[i][]=='y')
y++;
else
n++;
if(y>=)
break;
}
for(i=;i<;i++)
{
printf("%d\n",aa[i]);
fflush(stdout);
scanf("%s",a[i]);
if(a[i][]=='y')
y++;
else
n++;
if(y>=)
break;
}
if(y>=)
{
printf("composite\n");
fflush(stdout);
}
else
{
printf("prime\n");
fflush(stdout);
}
return ;
}
最新文章
- sdcms标签
- 用于基于 RPM 的 Linux 平台的 Java
- xbmc的静态链接办法
- 一些笔试题(C/C++)
- 如何生成DLL文件
- DCMTK3.6.0(MD支持库)安装说明
- Android中ScrollView嵌套GridView,解决GridView显示不全的问题
- Codeforces Round #365 (Div. 2) Mishka and trip
- 用Java实现向Cassandra数据库中插入和查询数据
- 核心概念 &mdash;&mdash; 服务容器
- hdoj 1035 Robot Motion
- SSM框架搭建web服务器实现登录功能(Spring+SpringMVC+Mybatis)
- service and intentservice
- Java并发编程--Fork/Join框架使用
- SpringMVC 学习-返回字符串中文乱码问题解决
- UVa 10405 &; POJ 1458 Longest Common Subsequence
- 201521123033《Java程序设计》第9周学习总结
- Crossin 8-3;8-4
- c++第0次作业
- <;转>;快速找到整数约数集方法<;python>;<;stackoverflow>;