题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2161

题意:判断n是不是素数,输入到0停止。题目规定1 2 都不是素数。

题解:筛素数。老题目。不过这次是普通筛23333.。之前做的题了。

 #include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
#define N 16001
bool prime[N];
void init(){
for(int i = ; i <= N ; i++){
prime[i] = true;
} for(int i = ; i < N; i++){
int tot = (i + ) / ;
for(int j = ; j <= tot; j++){
if(i % j == ){
prime[i] = false;
break;
}
}
}
prime[] = false;
prime[] = false; }
int main(){
init();
int n;
int cas = ;
while(scanf("%d",&n) , n>){
printf("%d: ",cas++);
if(prime[n])
printf("yes\n");
else
printf("no\n");
}
return ;
}

HduOJ 2162 - Primes的更多相关文章

  1. hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Time Limit: 2000/1000 MS (J ...

  2. [LeetCode] Count Primes 质数的个数

    Description: Count the number of prime numbers less than a non-negative number, n click to show more ...

  3. hduoj 1455 && uva 243 E - Sticks

    http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...

  4. projecteuler Summation of primes

    The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two milli ...

  5. leetcode-Count Primes 以及python的小特性

    题目大家都非常熟悉,求小于n的所有素数的个数. 自己写的python 代码老是通不过时间门槛,无奈去看了看大家写的code.下面是我看到的投票最高的code: class Solution: # @p ...

  6. Count Primes - LeetCode

    examination questions Description: Count the number of prime numbers less than a non-negative number ...

  7. [leetcode] Count Primes

    Count Primes Description: Count the number of prime numbers less than a non-negative number, n click ...

  8. Count Primes

    Count the number of prime numbers less than a non-negative number, n public int countPrimes(int n) { ...

  9. sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)

    The Android University ACM Team Selection Contest Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里 ...

随机推荐

  1. Python 多线程同步队列模型

    Python 多线程同步队列模型 我面临的问题是有个非常慢的处理逻辑(比如分词.句法),有大量的语料,想用多线程来处理. 这一个过程可以抽象成一个叫“同步队列”的模型. 具体来讲,有一个生产者(Dis ...

  2. JBoss、Tomcat、JBoss EAP、JBoss AS、wildfly,JBoss EAP安装部署,JBoss各个版本下载,JBoss允许远程访问

    感谢: https://www.cnblogs.com/invlong/p/5983334.html https://blog.csdn.net/mooncarp/article/details/78 ...

  3. Quartus II 使用 modelsim 仿真

    转自:http://www.cnblogs.com/emouse/archive/2012/07/08/2581223.html Quartus 中调用modelsim的流程 1. 设定仿真工具 as ...

  4. Java多态的本质

    今天复习了java多态,感觉收获颇多.多态的实现方式有两种,继承父类和实现接口.本质体现在重写上,不同的类重写时体现出不同的特征.编译时和运行时的不同上.编译时只能调用父类的方法,如果调用了子类独有的 ...

  5. 四(2)、springcloud之Ribbon负载均衡

    2.Ribbon负载均衡 ​ Ribbon在工作时分成两步第一步先选择 EurekaServer ,它优先选择在同一个区域内负载较少的server. 第二步再根据用户指定的策略,在从server取到的 ...

  6. vuex-along解决vuex中存储的数据在页面刷新之后失去的问题

    1. 为什么会失去? vuex可以看成是一个"提升变量"的一个工具,它是将state当做全局变量存储.F5刷新页面之后自然随着页面的刷新重新初始化state. 2. 如果解决数据保 ...

  7. win10无法设置移动热点的一种解决办法

    我的笔记本网卡为:Intel(R) Centrino(R) Wireless-N 2230 最近发现win10自带的移动热点无法启动了,一直显示无法设置热点 参考网上的教程,例如http://jing ...

  8. sqlldr details

    https://www.csee.umbc.edu/portal/help/oracle8/server.815/a67792/ch05.htm Loading into Empty and Non- ...

  9. nodejs mysql 连接数据库

    1.设计数据库 2.设计数据库表 3.下载MySQL模块 npm install --save mysql 4.编写代码 const mysql=require('mysql'); //1.连接 // ...

  10. Shell脚本 全局变量、局部变量

    在不同的作用域中,同名的变量不会相互干涉,就好像 A 班有个叫小明的同学,B 班也有个叫小明的同学,虽然他们都叫小明(对应于变量名),但是由于所在的班级(对应于作用域)不同,所以不会造成混乱.但是如果 ...