题目链接: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. 获取客户端IP地址-----以及--------线上开启redis扩展

    /** * 获取客户端IP地址 * @param integer $type 返回类型 0 返回IP地址 1 返回IPV4地址数字 * @return mixed */ function get_cl ...

  2. JS 变量 相关内容

    JS变量按存储方式区分为哪些类型?: js变量按照存储方式分为两种类型:值类型 和 引用类型 1.值类型(基本类型): 布尔值(boolean) . null .undefined .数值(numbe ...

  3. AndroidFine Error:Annotation processors must be explicitly declared now.

    环境 Android Studio 3.0 Gradle 3.0.0 gradle 4.1 Error Error:Execution failed for task ':app:javaPreCom ...

  4. spring 中 isolation 和 propagation 详解

    可以在XML文件中进行配置,下面的代码是个示意代码 <tx:advice id="txAdvice" transaction-manager="txManager& ...

  5. MySQL在Win10与Ubuntu下的安装与配置

        本文首发于cartoon的博客     转载请注明出处:https://cartoonyu.github.io/cartoon-blog     近段时间把自己电脑(win).虚拟机(Ubun ...

  6. pytest--fixture之参数化

    场景:测试用例执行时,有的用例需要登陆才能执行,有些用例 不需要登陆.setup和teardown无法满足.fixture可以.默认 scope(范围)function • 步骤: 1. 导入pyte ...

  7. pytest_fixture--scope="session"

    import pytest@pytest.fixture(scope="session")def login(): print("\n输入用户名密码登陆! configt ...

  8. Vue下渐变效果有时候失效

    记录一个问题:我在项目中给按钮设置一个渐变属性,调试的时候有时候有效果,有时候又没有,代码如下: .training-right-bmz { background: -webkit-linear-gr ...

  9. ES7/ES8 语法学习

    作为一个前端开发者,感觉需要学习的东西贼多,ES6刚学会用没多久,又得学习了解ES7/ES8新增的东西,这里是看了大佬们文章的一点点总结以及摘抄的内容,给自己当笔记使用 内容转载自:https://w ...

  10. .Net中Task使用来提高代码执行效率

    技术不断更新迭代,更高效的执行效率越来越被重视,所以对Task的使用进行了简单使用做了整理与大家分享. .Net 中有了Task后使多线程编程更简单使用和操作,下面粘上代码进行简单说明: /// &l ...