Eratosthenes筛法
来源:互联网 发布:存量房数据采集 编辑:程序博客网 时间:2024/06/08 09:04
一、
紫书内的代码
memset(vis,0,sizeof(vis));for(int i=2;i<=n;i++)for(int j=i*i;j<=n;j+=i)vis[j]=1;//优化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[maxn]; //记录素数 bool is_prime[maxn]; //记录是否是素数 int Eratosthenes(int n){ int num = 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[num++] = i; for(int j = i + i; j <= n; j += i) is_prime[j] = false; } } return p; //返回素数个数}
阅读全文
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筛法)
- 菜鸟程序员的超神之路
- C# 用正则表达式替换字符串中所有特殊字符
- 数据结构之最大子串
- 知乎上对理解阻塞非阻塞与同步异步的有趣解释
- Mediacodec获得视频流,写入H264文件
- Eratosthenes筛法
- [LeetCode] Two Sum III
- 计算机图形学 (二) 图元的属性
- javaee学习日记之java基础之接口,继承,抽象类
- jQuery源码学习笔记系列(二)
- Linux CentOS 6.3配置PHP开发环境
- 指定表名获取数据库内容-->泛型访问数据库-->注解方式访问数据库
- 【PAT】【Advanced Level】1080. Graduate Admission (30)
- Css sprites(Css精灵)