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项和, ...
随机推荐
- 洛谷P1200 [USACO1.1]你的飞碟在这儿Your Ride Is He…
题目描述 众所周知,在每一个彗星后都有一只UFO.这些UFO时常来收集地球上的忠诚支持者.不幸的是,他们的飞碟每次出行都只能带上一组支持者.因此,他们要用一种聪明的方案让这些小组提前知道谁会被彗星带走 ...
- 2018 MAC下安装Redis和Redis可视化工具RDM并连接Redis
实验环境:一台mac V:10.13.6 一.安装redis brew install redis 二.安装RDM 直接下载安装rdm dmg文件 链接: https://pan.baidu.com/ ...
- 原生js,一些小应用(逢10进一,生成V字,多个div抖动)
第一题:每隔10个div换一行.并且鼠标移入 改变opacity. <!DOCTYPE html> <html lang="en"> <head> ...
- mybatis入门截图二
-------------------- 线程不安全问题 首先明白什么是线程不安全: 举例:struts2中,每个action中都定义了model模型对象(action类中是全局对象的存在 数据域属 ...
- 流媒体播放器VLC SDL
http://www.cnblogs.com/lihuixian001/archive/2013/03/15/2957103.html https://wiki.videolan.org/Win32C ...
- php RSA 简单实现
这是rsa_private_key.pem-----BEGIN PRIVATE KEY----- MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC ...
- jquery-Kendo框架
从github上下载的包是完整的,可以根据readme.md上的步骤来操作 从官网下的那个包不是完整的,里面没有例子,只有源文件
- [asp.net]ashx中session存入,aspx为null的原因(使用flash uploader)
I am using uploadify to upload files, they automatically post to the handler. I then modify the sess ...
- 浙大PAT考试1013~1016(最伤的一次。。)
我能说我1016WA了几天都不得最后还是拿别人代码交的么. .. 真心找不到那个神数据.. . 自己把整个程序的流程都画出来了.细致推敲是木有问题的啊... 题目地址:点击打开链接 先从1013開始介 ...
- hdu 3177 Crixalis's Equipment
Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...