codeforces 679A Bear and Prime 100 交互
第一次交互题,记录一下吧
#include <cstdio>
#include <iostream>
#include <ctime>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const int N=1e3+;
const int INF=0x3f3f3f3f;
const int mod=1e9+;
int prime[];
bool vis[];
char s[];
int main()
{
for(int i=;i<=;++i)
if(!vis[i])
for(int j=i*i;j<=;j+=i)
vis[j]=;
int cnt=;
for(int i=;i<=;++i)
if(!vis[i])prime[++cnt]=i;
int ret=,x;
for(int i=;i<=cnt;++i){
printf("%d\n",prime[i]);
fflush(stdout);
scanf("%s",s);
if(s[]=='y')++ret,x=prime[i];
}
if(ret>=){
printf("composite\n");
fflush(stdout);
}
else if(ret==){
printf("2\n");
fflush(stdout);
scanf("%s",s);
if(s[]=='y'){
printf("composite\n");
fflush(stdout);
}
bool flag=;
for(int i=x*x;i<=;i*=x){
printf("%d\n",i);
fflush(stdout);
scanf("%s",s);
if(s[]=='y'){
flag=;
break;
}
}
if(flag)printf("composite\n");
else printf("prime\n");
fflush(stdout);
}
else{
int x=-;
for(int i=;i<=;i*=){
printf("%d\n",i);
fflush(stdout);
scanf("%s",s);
if(s[]=='y'){
x=i;
}
}
if(x==-||x==)printf("prime\n");
else printf("composite\n");
fflush(stdout);
}
return ;
}
codeforces 679A Bear and Prime 100 交互的更多相关文章
- Codeforces 679A Bear and Prime 100
链接:传送门 题意:给你一个隐藏数,这个隐藏数在[2,100]之间,现在最多可以询问20次,每次询问的是这个数是不是隐藏数的底数,是为yes,不是为no,每次询问后都需要flush一下输出缓冲区,最后 ...
- Codeforces A - Bear and Prime 100(交互题)
A - Bear and Prime 100 思路:任何一个合数都可以写成2个以上质数的乘积.在2-100中,除了4,9,25,49外都可以写成两个以上不同质数的乘积. 所以打一个质数加这四个数的表: ...
- 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) C. Bear and Prime 100 水题
C. Bear and Prime 100 题目连接: http://www.codeforces.com/contest/680/problem/C Description This is an i ...
- codeforces 680C C. Bear and Prime 100(数论)
题目链接: C. Bear and Prime 100 time limit per test 1 second memory limit per test 256 megabytes input s ...
- 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]范围内的非 ...
- 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 385C Bear and Prime Numbers
题目链接:Codeforces 385C Bear and Prime Numbers 这题告诉我仅仅有询问没有更新通常是不用线段树的.或者说还有比线段树更简单的方法. 用一个sum数组记录前n项和, ...
随机推荐
- HDU 1695 GCD (容斥原理+欧拉函数)
题目链接 题意 : 从[a,b]中找一个x,[c,d]中找一个y,要求GCD(x,y)= k.求满足这样条件的(x,y)的对数.(3,5)和(5,3)视为一组样例 . 思路 :要求满足GCD(x,y) ...
- 【转载】synchronized 与 Lock 的那点事
最近在做一个监控系统,该系统主要包括对数据实时分析和存储两个部分,由于并发量比较高,所以不可避免的使用到了一些并发的知识.为了实现这些要求,后台使用一个队列作为缓存,对于请求只管往缓存里写数据.同时启 ...
- Win7-其中的文件夹或文件已在另一个程序中打开
Win7-其中的文件夹或文件已在另一个程序中打开 如何解决Win7系统在删除或移动文件时提示,“操作无法完成,因为其中的文件夹或文件已在另一个程序中打开,请关闭该文件夹或文件,然后重试”. 步骤阅 ...
- 读书笔记:7个示例科普CPU Cache
本文转自陈皓老师的个人博客酷壳:http://coolshell.cn/articles/10249.html 7个示例科普CPU Cache (感谢网友 @我的上铺叫路遥 翻译投稿) CPU cac ...
- lintcode 中等题:Max Points on a Line 最多有多少个点在一条直线上
题目 最多有多少个点在一条直线上 给出二维平面上的n个点,求最多有多少点在同一条直线上. 样例 给出4个点:(1, 2), (3, 6), (0, 0), (1, 3). 一条直线上的点最多有3个. ...
- C 语言学习guideline
Kernighan和Ritchie的<The C Programming Language>(中译名<C程序设计语言>)堪称经典中的经典,不过旧版的很多内容都已过时,和现在的标 ...
- java 调用 phantomjs
java 调用 phantomjs 2014-11-21 13:55 2034人阅读 评论(2) 收藏 举报 分类: phantomjs(2) 日前有采集需求,当我把所有的对应页面的链接都拿到手, ...
- Linux 线程属性函数总结
1.初始化一个线程对象的属性 int pthread_attr_init(pthread_attr_t *attr); 返回值:若是成功返回0,否则返回错误的编号 形 参: attr 指向一个线程属性 ...
- Java中boolean型变量的默认值问题
1.首先分析Java中的三种不同变量的区别,如下表所示 概念 默认值 其他 类变量 也叫静态变量,是类中独立于方法之外的变量 用static 修饰 有默认初始值,系统自动初始化. 如boolean ...
- “LC.exe已退出,代码为-1错误”解决办法
有的时间,在项目中编辑运行以后,竟然出错了,错误提示就是: “LC.exe”已退出,代码为 -1. 具体解决方法如下: 因为证书的原因,把项目中“properties”目录下的“license.lic ...