Codeforces 679A Bear and Prime 100
链接:传送门
题意:给你一个隐藏数,这个隐藏数在[2,100]之间,现在最多可以询问20次,每次询问的是这个数是不是隐藏数的底数,是为yes,不是为no,每次询问后都需要flush一下输出缓冲区,最后判断这个数是不是素数。
思路:直接打出50以内的素数表,挨个进行询问,用计数器记录出现的因子个数,如果>1则说明为合数,需要特殊处理4,9,16,25,36,49,例如 49 --> 1 7 49 计数器1,但此数仍为合数。
/*************************************************************************
> File Name: a.cpp
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年04月18日 星期二 01时19分49秒
************************************************************************/
#include<bits/stdc++.h>
using namespace std;
int p[21] = { 2,3,4,5,7,9,11,13,17,19,23,25,29,31,37,41,43,47,49 };
char order[5];
int main(){
int sum = 0;
for(int i=0;i<19;i++){
printf("%d\n",p[i]);
fflush(stdout);
scanf("%s",order);
if(order[0] == 'y') sum++;
}
if(sum>1){
printf("composite\n");
fflush(stdout);
}
else{
printf("prime\n");
fflush(stdout);
}
return 0;
}
Codeforces 679A Bear and Prime 100的更多相关文章
- codeforces 679A Bear and Prime 100 交互
第一次交互题,记录一下吧 #include <cstdio> #include <iostream> #include <ctime> #include <v ...
- 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项和, ...
随机推荐
- Zookeeper分布式锁解决方案具体代码
定义一个公共资源订单生成类: package com.itmayiedu.lock; import java.text.SimpleDateFormat; import java.util.Date; ...
- 转[总结]FFMPEG视音频编解码零基础学习方法 .
http://blog.csdn.net/leixiaohua1020/article/details/15811977 在CSDN上的这一段日子,接触到了很多同行业的人,尤其是使用FFMPEG进行视 ...
- 【hiho一下第二周 】Trie树
[题目链接]:http://hihocoder.com/problemset/problem/1014 [题意] [题解] 在字典树的域里面加一个信息cnt; 表示这个节点下面,记录有多少个单词; 在 ...
- 【codeforces 719E】Sasha and Array
[题目链接]:http://codeforces.com/contest/719/problem/E [题意] 给你一个数列,有两种操作1 l r x 给[l,r]区间上的数加上x, 2 l r 询问 ...
- BIO、NIO、AIO
一.基础概念 IO操作分为两步:1.发起IO请求:2.执行具体IO操作: 同步和异步的区别是数据访问时进程是否阻塞或者说在执行真正IO操作时,数据能够立即返回就是异步,否则就是同步,同步和异步发生在I ...
- rabbitMQ学习笔记(五) 消息路由
生产者会生产出很多消息 , 但是不同的消费者可能会有不同的需求,只需要接收指定的消息,其他的消息需要被过滤掉. 这时候就可以对消息进行过滤了. 在消费者端设置好需要接收的消息类型. 如果不使用默认的E ...
- ASP.Net Cookie总结
Cookie是一段文本信息,在客户端存储 Cookie 是 ASP.NET 的会话状态将请求与会话关联的方法之一.Cookie 也可以直接用于在请求之间保持数据,但数据随后将存储在客户端并随每个请求一 ...
- 香蕉派 Banana pi BPI-M2 四核开源单板计算机.
Banana PI BPI-M2 是一款四核高性能单板计算机,Banana PI BPI-M2是一款比树莓派更强悍的四核Android4.4产品. Banana PI BPI-M2兼容性强大,能 ...
- Linux安装vmtools
unbantu下,先把DVD的Vmwarew.gz,文件拷贝到tmp文件.然后 tar zxf VMware Tools-0....... ls cd ./intall.pl 有个文件,先拷贝到roo ...
- ScrollView+RadioGroup
今天要分享一下关于动态添加RadioButton的东西: 要实现的效果就是,这个控件可以左右滑动,里面的按钮都是互斥的,类似RadioButton,我的第一反应就是用ScrollView+RadioG ...