codeforces 680C 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 题意: 底数是[2,100]中的数,现在你最多询问20次,询问为这个数是不是底数的因数,最后判断这个数是不是素数; 思路: [2,100]的素数有20+个,不能都询问一遍,可以询问[2,50]里面的素数,如果全都是no就是大于50的素数,如果yes的个数大于1,那么一定不是素数,如果是一个yes,那么这个数可能是小于50的素数,也可能像4,8,9这种数,那么再判断一下i*i就好了;具体的看代码吧; AC代码:
//#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio> using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<''||CH>'';F= CH=='-',CH=getchar());
for(num=;CH>=''&&CH<='';num=num*+CH-'',CH=getchar());
F && (num=-num);
}
int stk[], tp;
template<class T> inline void print(T p) {
if(!p) { puts(""); return; }
while(p) stk[++ tp] = p%, p/=;
while(tp) putchar(stk[tp--] + '');
putchar('\n');
} const LL mod=1e9+;
const double PI=acos(-1.0);
const LL inf=1e14;
const int N=1e5+; int n,a,t[],flag[];
int prime()
{
for(int i=;i<=;i++)
{
if(!flag[i])
{
for(int j=*i;j<=;j+=i)
flag[j]=;
}
}
//cout<<"#"<<endl;
return ;
}
int main()
{
prime();
string s;
int num=;
for(int i=;i<=;i++)
{
if(!flag[i])
{
printf("%d\n",i);
fflush(stdout);
cin>>s;
if(s=="yes")
{
num++;
if(i*i<=)
{
printf("%d\n",i*i);
fflush(stdout);
cin>>s;
if(s=="yes")num++;
}
}
}
}
if(num<=)cout<<"prime"<<"\n";
else cout<<"composite"<<"\n";
fflush(stdout); return ;
}
codeforces 680C 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 ...
- 680C. 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) C. Bear and Prime 100 水题
C. Bear and Prime 100 题目连接: http://www.codeforces.com/contest/680/problem/C Description This is an i ...
- Codeforces A - Bear and Prime 100(交互题)
A - Bear and Prime 100 思路:任何一个合数都可以写成2个以上质数的乘积.在2-100中,除了4,9,25,49外都可以写成两个以上不同质数的乘积. 所以打一个质数加这四个数的表: ...
- codeforces 356 div2 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】679 A. Bear and Prime 100
[题目]A. Bear and Prime 100 [题意]有一数字x,每次可询问一个数字y是否x的因子,最后输出数字x是否素数,要求询问次数<=20. [题解]容易发现[2,100]范围内的非 ...
- 暑假练习赛 006 B Bear and Prime 100
Bear and Prime 100Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:262144KB ...
- CF #356 div1 A. Bear and Prime 100
题目链接:http://codeforces.com/contest/679/problem/A CF有史以来第一次出现交互式的题目,大致意思为选择2到100中某一个数字作为隐藏数,你可以询问最多20 ...
- Codeforces 679A Bear and Prime 100
链接:传送门 题意:给你一个隐藏数,这个隐藏数在[2,100]之间,现在最多可以询问20次,每次询问的是这个数是不是隐藏数的底数,是为yes,不是为no,每次询问后都需要flush一下输出缓冲区,最后 ...
随机推荐
- [读书笔记]SQL约束
目的:通过在列级或表级设置约束,确保数据符合某种数据完整性规则 实现:数据库主动地检查维护数据的完整性 手段:约束,数据类型,触发器 --------------------------------- ...
- __declspec,__cdecl,__stdcall区别和作用
_cdecl和__stdcall都是函数调用规范(还有一个__fastcall),规定了参数出入栈的 顺序和方法,如果只用VC编程的话可以不用关心,但是要在C++和Pascal等其他语言通信的时候就要 ...
- 如何在DigitalOcean安装Ghost
查看原文: http://leancodingnow.com/how-to-install-ghost-on-digital-ocean-vps/ 这篇文章主要讲一下如何在DigitalOcean V ...
- Lazy Loading Images
Use a blank.gif as the src of images, and include the width and height of the final image. HTML: < ...
- d3.js <一>
<html> <head> <meta charset="utf-8"> <title>HelloWorld</title&g ...
- android用NDK编译出so最简单的方法
其实只要是有个jni的文件夹,再放个Android.mk LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := hell ...
- jQuery对象入门级介绍
你是否曾经见过像 $(".cta").click(function(){})这样的JavaScrip代码?或许你还会思考下 $('#X') 是什么,如果看到这些你都觉得摸不着头脑 ...
- Codeforces Gym 100531D Digits 暴力
Problem D. Digits 题目连接: http://codeforces.com/gym/100531/attachments Description Little Petya likes ...
- busybox配置telnetd
busybox配置telnetd的问题 进入busybox源码文件夹,选择telnet,telnetd.后确保在ramdisk的sbin文件夹下存在inetd和in.telnetd或telned.在r ...
- asp.net 获取url
string url = Request.Url.ToString(); this.ImageLogo.ImageUrl = "http://" + Request.Url.Aut ...