题目链接: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. GitHub 万星推荐:黑客成长技术清单

    GitHub 万星推荐:黑客成长技术清单 导语:如果你需要一些安全入门引导,“Awesome Hacking”无疑是最佳选择之一. 最近两天,在reddit安全板块和Twitter上有个GitHub项 ...

  2. selenium工作的大概原理

    selenium的原理是什么? selenium的原理涉及到3个部分,分别是 浏览器 driver: 一般我们都会下载driver client: 也就是我们写的代码 client其实并不知道浏览器是 ...

  3. git分布式版本控制系统权威指南学习笔记(六):git reset、get stash、git checkout总结

    文章目录 1. 概述 2. 如何把修改暂存起来,留着以后使用? 2.1 使用场景 2.2 git stash 暂存进度 2.3 查看进度 2.4 恢复进度 3. 如何撤销工作区的修改? 4. 如何把暂 ...

  4. Day 22: 软件开发目录设计规范

    软件开发目录设计 对于提高项目可读性.可维护性的要求就很高了.”项目目录结构”其实也是属于”可读性和可维护性”的范畴,我们设计一个层次清晰的目录结构,就是为了达到以下两点: 可读性高: 不熟悉这个项目 ...

  5. keepalived 参数中文说明

    GLOBAL CONFIGURATION Global definitions global_defs { notification_email { admin@example.com } notif ...

  6. B-彻底删除卸载Ubuntu中的MySQL并重新安装(已验证)

    Ubuntu-16.04,MySQL-5.7,寻找多篇有关如何彻底卸载删除MySQL的博文, 最终验证下面转发博文真实有效,推荐! https://www.jianshu.com/p/c76b31df ...

  7. @ApiImplicitParams、ApiImplicitParam的使用

    @ApiImplicitParam:作用在方法上,表示单独的请求参数 参数: 1. name :参数名. 2. value : 参数的具体意义,作用. 3. required : 参数是否必填. 4. ...

  8. Android的WebView通过JS调用java代码

    做项目时候会遇到我们用WebView 打开一个web,希望这个web可以调用自己的一些方法,比如我们在进一个web页面,然后当我们点击web上的某个按钮时,希望能判断当前手机端是否已经登录,如果未登录 ...

  9. Kettle使用kettle.properties

    kettle.properties 是一个变量文件,这个文件我使用的最多的地方是保存 “数据库连接” 用户名和密码. 如果不用这个文件,那么使用“数据库连接”时,需要硬编码写到文件里. 有一天dba告 ...

  10. createBottomTabNavigator: 怎么在切换tab的时候让页面重新渲染

    1.import withNavigationFocus from react-navigation to your class . 2.hen export your like this : exp ...