题意:

给一个数n,问1~n内有多少个素数

题目:

Write a program which reads an integer n and prints the number of prime numbers which are less than or equal to n. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.

Input

Input consists of several datasets. Each dataset has an integer n (1 ≤ n ≤ 999,999) in a line.

The number of datasets is less than or equal to 30.

Output

For each dataset, prints the number of prime numbers.

Sample Input

10
3
11

Output for the Sample Input

4
2
5

分析:

打个素数筛就行

AC模板:

#include<stdio.h>
#include<string.h>
#include<map>
#include<algorithm>
using namespace std;
const int M=1e6+10;
int n;
int dp[M],book[M];
map<int,int>mp;
void init()
{for(int i=2; i<M; i++){if(!book[i]){mp[i]=1;for(int j=i; j<M; j+=i)book[j]=1;}}for(int i=1; i<M; i++){dp[i]=dp[i-1];if(mp[i])dp[i]++;}
}
int main()
{init();while(~scanf("%d",&n)){printf("%d\n",dp[n]);}return 0;
}

备战ccpc分站赛ing ,题目分析简略,见谅,转载请注明出处。。。。。

Prime Number Aizu - 0009(素数筛)相关推荐

  1. 22行代码AC_Prime Number Aizu - 0009(素数筛)(解题报告)

    励志用更少的代码做更高效的表达 题意: 给一个数n,问1~n内有多少个素数 题目: Write a program which reads an integer n and prints the nu ...

  2. 质数(prime number)又称素数,有无限个。质数定义为在大于1的自然数中,除了1和它本身以外不再有其他因数的数称为质数。合数(Composite number)是与质数对应的概念,在大于1

    #include<bits/stdc++.h> using namespace std; int main() {     int x,flag=0;     cin>>x; ...

  3. FZU 1649 Prime number or not (Miller-Rabin素数测试)

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=1649 题目大意:很直接,判断一个数n(2<=n<=10^18)是不是素数.   当n达到long ...

  4. 素数筛 Prime sieve

    文章目录 素数筛 Prime sieve 一.素数的判定 二.埃氏筛法 三.欧拉筛法 四.六倍原理 素数筛 Prime sieve 素数又称质数:一个大于 1 的自然数,除了 1 和它自身外,不能被其 ...

  5. FZU 1649 Prime number or not (大素数测试)

    题目链接 Problem 1649 Prime number or not Accept: 661    Submit: 3016 Time Limit: 2000 mSec    Memory Li ...

  6. Mysterious Bacteria(唯一质因子解+素数筛)

    原题目: Dr. Mob has just discovered a Deathly Bacteria. He named it RC-01. RC-01 has a very strange rep ...

  7. 面试官本拿求素数搞我,但被我优雅的“回击“了(素数筛)

    原创公众号(希望能支持一下):bigsai 转载请联系bigsai 文章收录在github 求star 前言 现在的面试官,是无数开发者的梦魇,能够吊打面试官的属实不多,因为大部分面试官真的有那么那几 ...

  8. 筛表合集(素数筛 欧拉函数筛 莫比乌斯函数筛)

    [目录] 一.素数筛 1.素数判断 2.素数普通筛 3.素数线性筛 4.素数区间筛 二.欧拉函数筛 三.莫比乌斯函数筛 [素数筛] 1.直接判定质数 bool judgePrime( int num ...

  9. Project Euler 97 :Large non-Mersenne prime 非梅森大素数

    Large non-Mersenne prime The first known prime found to exceed one million digits was discovered in ...

最新文章

  1. boost::BoostRegexConcept相关的测试程序
  2. netty系列之:channelPipeline详解
  3. mysql+地图网格数据下载_echarts 中国各省市 echarts地图数据,含世界地图
  4. CSS样式表的规划与组织
  5. HTML5游戏引擎Playcraft将于近日正式启动
  6. java的隐藏函数_java – 隐藏子级数据成员的父成员函数
  7. centos7安装mysql允许远程连接_CentOS7安装Mysql并配置远程访问
  8. [转] C# 绘制报表,使用Graphics.DrawString 方法
  9. 前端都该懂的浏览器工作原理,你懂了吗?
  10. Tomcat6.0配置集合
  11. FPGA图像处理 两路sensor的色调不一致
  12. java数字小游戏_java数字小游戏
  13. STM32的备份寄存器和控制状态寄存器
  14. echarts改变颜色属性的demo
  15. java游戏编程源代码_JAVA小游戏编程-源代码
  16. GoogleAnalytics文档
  17. 单片机原理与接口技术(ESP8266/ESP32)机器人类草稿
  18. 优秀开源项目之二:流媒体直播系统Open Broadcaster Software
  19. NVIDIA Jetson: GStreamer 和 openMAX(gst-omx) 插件
  20. RNA m6A修饰问题汇总(第二期)

热门文章

  1. TCP之三次握手和四次挥手过程
  2. C语言之获取32字节随机数的字符串
  3. linux c之perror和exit使用总结
  4. 单身的原因终于找到了!原来是这几个......
  5. 史上最丧心病狂的商品定价套路:如何从数学角度,榨干你身上的每一分钱
  6. 北大清华团队编写!200多个科学实验+视频,和爸爸一起在家做
  7. 看见到洞见之引子(一)机器学习算法
  8. 免安装免配置 还免费的Spark 集群 --Databrickes Spark Clould
  9. SparkSQL DataFrame进阶篇
  10. linux硬盘转windows7,记——第一次上手UEFI电脑,将mbr硬盘的Windows7和Linux转为gpt+uefi启动...