Eratosthenes筛法
来源:互联网 发布:美国经济数据日历 编辑:程序博客网 时间:2024/06/08 09:50
Eratosthenes筛法
#include <stdio.h>#include <string.h>#include <math.h>//Eratosthenesconst int maxn = 10000000 + 5;const int maxp = 700000;int vis[maxn];int prime[maxp];void sieve(int n) //screen out the prime numbers{ int m = sqrt(n + 0.5); memset(vis, 0, sizeof(vis)); for(int i = 2; i <= m; i++) if(!vis[i]) for(int j = i * i; j <= n; j += i) vis[j] = 1;}int prime_numbers(int n){ sieve(n); int c = 0; //the number of prime numbers for(int i = 2; i <= n; i++) if(!vis[i]) { prime[c] = i; c++; } return c;}//the end of Eratosthenesint main(){ int t; while(scanf("%d", &t) != EOF) { printf("total prime numbers: %d\n\n", prime_numbers(t)); for(int i = 0; i < prime_numbers(t); i++) printf("%d\n", prime[i]); } return 0;}
阅读全文
0 0
- Eratosthenes筛法
- Eratosthenes筛法
- Eratosthenes筛法
- Eratosthenes筛法
- Eratosthenes筛法
- Eratosthenes筛法
- Eratosthenes筛法,求素数
- Eratosthenes筛法--Haskell实现
- Eratosthenes筛法 素数筛
- 埃拉托色尼(Eratosthenes)筛法
- Eratosthenes(埃拉托色尼)筛法
- C++ 数论-Eratosthenes筛法
- Eratosthenes筛法(埃氏筛法)
- Eratosthenes
- Eratosthenes
- Eratosthenes筛法和Euler筛法
- Eratosthenes筛法(素数筛法)
- 找质数算法(Sieve of Eratosthenes筛法)
- spring源码解析-AOP原理
- 指定代码放哪个cpu运行
- Sequence
- 解决springMVC中Get请求乱码的问题
- AndroidStudio的CMake开发时遇到的异常及解决方案
- Eratosthenes筛法
- 基本Makefile编写举例
- 受限玻尔兹曼机(Restricted Boltzmann Machine)分析
- 解决ajax请求过滤器重定向不跳转
- 面试总结:关于数据库范式的一点理解
- Monkey and Banana HDU
- gson解析字符串toBean
- Eclipse +Scala+Maven+Spark开发模式
- macvlan 网络结构分析