厄拉多塞筛算法
来源:互联网 发布:婚纱照怎样拍好看知乎 编辑:程序博客网 时间:2024/05/26 19:19
package abc;public class ch221 { public static long sh221(int n){<span style="white-space:pre"></span> int[] a=new int[n];<span style="white-space:pre"></span> int sum=0;<span style="white-space:pre"></span> for(int i=0;i<a.length;i++){<span style="white-space:pre"></span> a[i]=i+1;<span style="white-space:pre"></span> }<span style="white-space:pre"></span> for(int i=(int) Math.sqrt(n);i>=2;i--){<span style="white-space:pre"></span> for(int j=i+1;j<n;j++){<span style="white-space:pre"></span> if((a[j]%i)==0){<span style="white-space:pre"></span> a[j]=0;<span style="white-space:pre"></span> }<span style="white-space:pre"></span> }<span style="white-space:pre"></span> }<span style="white-space:pre"></span> for(int i=0;i<a.length;i++){<span style="white-space:pre"></span> if(a[i]!=0){<span style="white-space:pre"></span> System.out.println(a[i]);<span style="white-space:pre"></span> sum+=a[i];<span style="white-space:pre"></span> }<span style="white-space:pre"></span> <span style="white-space:pre"></span> }<span style="white-space:pre"></span> return sum; } public static void main(String[] args) {<span style="white-space:pre"></span>long s=sh221(200);<span style="white-space:pre"></span>System.out.println(s);<span style="white-space:pre"></span>}}
0 0
- 厄拉多塞筛算法
- 厄拉多塞筛算法及实现
- 算法
- 算法
- 算法
- 算法
- 算法
- 算法
- 算法
- 算法
- 算法
- 算法
- 算法
- 算法
- 算法
- 算法
- 算法
- 算法
- 在Linux用户空间做内核空间做的事情
- 使用eclipse简单的搭建ssh框架
- 第二周项目 0-宣告“主权”
- [机器学习]斯坦福公开课-第1,2课-监督与非监督矩阵以及梯度下降
- Codevs5288 航线设计(动态规划加强版) 解题报告
- 厄拉多塞筛算法
- PDO的学习与使用
- Android之自定义圆形进度条
- Class.forName()用法详解
- UOJ #242. 【UR #16】破坏蛋糕
- [dsu] CSU1811: Tree Intersection
- 关于qt中的QLinearGradient 线性渐变的使用
- HTTPS协议下两种接受自定义Server Certificates的方式
- cocos2d-x学习 第一天