筛法打素数表
2017-08-14 15:40
405 查看
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <map> #include <string> #include <cstring> #include <ctime> #define ms(a,b) memset(a,b,sizeof(a)) using namespace std; typedef long long ll; const int NP = 1000005; int ispri[NP] = {}, prime[NP], pcnt = 0; void getprime() { ispri[0] = ispri[1] = 1; for (long long i = 2; i < NP; i++) if (ispri[i] == 0) { prime[++pcnt] = i; for (long long j = i * i; j < NP; j += i) { ispri[j] = 1; } } } int main() { ///freopen("data.txt", "r", stdin); freopen("output.txt", "w", stdout); getprime(); for (int i = 1; i <= pcnt; i++) { cout << prime[i] << endl; } return 0; }
相关文章推荐
- 素数 约数 欧拉函数 筛法
- 1029: 用筛法求之N内的素数。(附常见的四种解决方案)
- 素数密度——区间筛法(详解)
- hdu2098 分拆素数和 筛法
- 筛法求素数个数
- poj3006 Dirichlet's Theorem on Arithmetic Progressions 欧拉筛法素数打表,杂题
- 二次筛法找区间两点特别大(超过10亿)的素数-POJ2689
- HDU 6069 Counting Divisors (素数+筛法)
- 筛法求素数
- 埃氏筛法 —— 对素数的使用
- Eratosthenes筛法求1-100之间的素数
- 筛法求1000000以内素数个数---时间复杂度为o(n)
- poj 2689 Prime Distance (素数二次筛法)
- 筛法求素数
- (Relax 数论1.11)POJ 1595 Prime Cuts(欧拉筛法: 输出1~n区间中中间的2C个素数)
- (Relax 数论1.13)POJ 2909 Goldbach's Conjecture(欧拉筛法的应用:给出一个偶数,要求在这个偶数的范围内,有几对素数和是等于这个偶数的,注意素数对的不重复性! )
- 素数的三种筛法比较
- poj 2689 Prime Distance 筛法+区间筛素数
- MOOC清华《程序设计基础》第4章第1题:找出ab间的素数(用筛法做)
- 求质数(Prime Number 素数)的方法——厄拉多塞筛法