链接:传送门

题意:给你一个隐藏数,这个隐藏数在[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的更多相关文章

  1. codeforces 679A Bear and Prime 100 交互

    第一次交互题,记录一下吧 #include <cstdio> #include <iostream> #include <ctime> #include <v ...

  2. Codeforces A - Bear and Prime 100(交互题)

    A - Bear and Prime 100 思路:任何一个合数都可以写成2个以上质数的乘积.在2-100中,除了4,9,25,49外都可以写成两个以上不同质数的乘积. 所以打一个质数加这四个数的表: ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 【CodeForces】679 A. Bear and Prime 100

    [题目]A. Bear and Prime 100 [题意]有一数字x,每次可询问一个数字y是否x的因子,最后输出数字x是否素数,要求询问次数<=20. [题解]容易发现[2,100]范围内的非 ...

  8. 680C. Bear and Prime 100 数学

    C. Bear and Prime 100 time limit per test:1 second memory limit per test:256 megabytes input:standar ...

  9. Codeforces 385C Bear and Prime Numbers

    题目链接:Codeforces 385C Bear and Prime Numbers 这题告诉我仅仅有询问没有更新通常是不用线段树的.或者说还有比线段树更简单的方法. 用一个sum数组记录前n项和, ...

随机推荐

  1. 一个简单的 PC端与移动端的适配(通过UA)

    只需在header引用个js文件, 原理就是判断UA里面的标识.  加下面代码添加到js文件,在头文件引用即可 var Pc_url = 'http://www.baidu.com'; //PC端网址 ...

  2. 【codeforces 799A】Carrot Cakes

    [题目链接]:http://codeforces.com/contest/799/problem/A [题意] 你有一个烤炉; 每t秒能同时烤出k个蛋糕; 你可以在第一个烤炉在烤的时候;同时花费d秒建 ...

  3. Emgu cv人脸检测识别

    Emgu cv人脸检测识别 1.开发平台:WIN10 X64    VS2012    Emgucv版本:3.1 2.先给大家分享一个官网给的示例源代码: https://ncu.dl.sourcef ...

  4. redis 五大数据类型

    一.String set : 添加数据 get : 获得指定 key 的 value del : 删除指定 key append : 往字符串后面添加       append k1 12345    ...

  5. 工具-VMWARE技巧-桥接连外网-WIN7

    使用虚拟机wmware如何连接宿主主机 最简单的方法,使用直接连接主机的模式,然后把宿主机的IP更改为和虚拟机同一个网段的机器就行 但是既要上网,有要连接虚拟机,就需要使用桥接,在编辑->虚拟网 ...

  6. 操作服务器及MySQL数据库可以使其远程链接

    转自原文操作服务器及MySQL数据库可以使其远程链接 一般情况分三个地方准备,MySQL数据库,防火墙,还有你的服务器主机的准备 操作系统为centos6.5.其他系统大致差不多. 1:在服务器中安装 ...

  7. USACO holstein 超时代码

    /* ID:kevin_s1 PROG:holstein LANG:C++ */第八组数据跪了.半天都不出结果 #include <iostream> #include <cstdi ...

  8. TS3

    let [first, ...rest] = [1, 2, 3, 4]; console.log(first); // outputs 1 console.log(rest); // outputs ...

  9. poj--3159--Candies(简单差分约束)

    Candies Time Limit: 1500MS   Memory Limit: 131072K Total Submissions: 26888   Accepted: 7398 Descrip ...

  10. 【刷题笔记】LeetCode 222. Count Complete Tree Nodes

    题意 给一棵 complete binary tree,数数看一共有多少个结点.做题链接 直观做法:递归 var countNodes = function(root) { if(root===nul ...