Aizu 0009 Prime Number
来源:互联网 发布:程序员数学 编辑:程序博客网 时间:2024/04/30 19:25
Prime Number
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, 7.
Input
Input consists of several datasets. Each dataset has an integer n (n ≤ 999999) in a line.
The number of datasets ≤ 30.
Output
For each dataset, prints the number of prime numbers.
Sample Input
10
3
11
Output for the Sample Input
4
2
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, 7.
Input
Input consists of several datasets. Each dataset has an integer n (n ≤ 999999) in a line.
The number of datasets ≤ 30.
Output
For each dataset, prints the number of prime numbers.
Sample Input
10
3
11
Output for the Sample Input
4
2
5
给出一个数n,求n以内素数的个数。我用的埃氏筛法
#include <cstdio>#include <iostream>using namespace std;int prime[1000005];bool is_prime[1000005];int seve(int n){ int p=0; for(int i=0;i<=n;i++) is_prime[i]=true; is_prime[0]=is_prime[1]=false; for(int i=2;i<=n;i++) { if(is_prime[i]) { prime[p++]=i; for(int j=2*i;j<=n;j+=i) is_prime[j]=false; } } return p;}int main(void){ int n; while(scanf("%d",&n)!=EOF) { printf("%d\n",seve(n)); } return 0;}
0 0
- Aizu 0009 Prime Number
- Aizu 0009 Prime Number【统计素数】
- Aizu - NTL_1_A Prime Factorize
- Prime Number
- Prime number
- Prime Number
- Prime Number
- prime number
- AOJ 0009 Prime Number (埃氏筛法)
- [数学] AOJ 0009 素数筛选 Prime Number
- Aizu
- Aizu
- Aizu
- Aizu
- Aizu
- Aizu
- Aizu
- Aizu
- iOS 之选择器(Selector)
- neusoft.shixi__任务一
- 《人工智能教程(张仰森)》(二)
- box草稿2--个人技能发展计划
- select
- Aizu 0009 Prime Number
- Android面试题(含答案)
- Ralink RT3070 AP移植笔记
- Eclipse SVN插件安装
- Android源码解析系列
- Tcl/Tk 进度系统 可以点状态与时间
- 自定义propertygrid弹出属性编辑框
- IPHONE强制重启
- uva 10256(凸包)