Algorithm Gossip: Eratosthenes筛选求质数
来源:互联网 发布:淘宝客服招聘上海 编辑:程序博客网 时间:2024/06/06 08:57
package main01;
import java.util.ArrayList;
public class CoreJava05 {
/**
* @param args
}
public static ArrayList<Integer> Eratosthenes(int number) {
ArrayList<Integer> list = new ArrayList<Integer>();
int count = 0;
int i = 0;
int j = 0;
int array[] = new int[number + 1];
// 初始化数组不考虑1
for (i = 2; i <= array.length - 1; i++) {
array[i] = 1;
}
for (i = 2; i <= array.length - 1; i++) {
// 从2开始凡是为2得倍数,3的倍数,4的倍数。。。。。。则将该值设为0
for (j = i * i; j <= array.length - 1; j += i) {
array[j] = 0;
}
}
//将数组中为1的即为质数的下标保存在list集合中
for (i = 2; i <= array.length - 1; i++) {
if (array[i] == 1) {
list.add(i);
}
}
return list;
}
}
import java.util.ArrayList;
public class CoreJava05 {
/**
* @param args
* Algorithm Gossip: Eratosthenes筛选求质数 解题思路:
过滤2的倍数,3的倍数,5的倍数,7的倍数.........N
*/
// TODO Auto-generated method stub
//测试方法代码所用,
}
public static ArrayList<Integer> Eratosthenes(int number) {
ArrayList<Integer> list = new ArrayList<Integer>();
int count = 0;
int i = 0;
int j = 0;
int array[] = new int[number + 1];
// 初始化数组不考虑1
for (i = 2; i <= array.length - 1; i++) {
array[i] = 1;
}
for (i = 2; i <= array.length - 1; i++) {
// 从2开始凡是为2得倍数,3的倍数,4的倍数。。。。。。则将该值设为0
for (j = i * i; j <= array.length - 1; j += i) {
array[j] = 0;
}
}
//将数组中为1的即为质数的下标保存在list集合中
for (i = 2; i <= array.length - 1; i++) {
if (array[i] == 1) {
list.add(i);
}
}
return list;
}
}
0 0
- Algorithm Gossip: Eratosthenes筛选求质数
- Algorithm Gossip (15) 筛选求质数(Eratosthenes )
- Algorithm Gossip: 筛选求质数
- Eratosthenes筛选求质数
- 14 Eratosthenes 筛选求质数
- Eratosthenes筛选法计算质数
- Sieve of Eratosthenes求质数
- 筛选求质数
- 筛选法求质数
- Eratosthenes筛选法求素数的算法
- Eratosthenes筛选法求素数的算法
- 质数筛选(详细解释以及模板)(Eratosthenes)
- 第六章课后题:质数Eratosthenes筛选法
- 用筛选法求质数
- PHP筛选法求质数。
- 求质数的筛选算法
- 筛选法求质数(注解)
- 求质数中的筛选思想
- Fragment加动画后快速点击屏幕进行切换 产生的异常: java.lang.IllegalStateException: No host
- GetModuleHandle,AfxGetInstanceHandle使用区别
- eclipse的常用快捷键
- CSU 1558 和与积
- UVA445 - Marvelous Mazes
- Algorithm Gossip: Eratosthenes筛选求质数
- RequireJS 2.x —— 基础使用
- ZenGl跨平台图形引擎介绍
- MFC消息映射与命令传递
- WOJ1006 - Language of Animals
- 图解Oracle 12c创建数据挖掘(Data Miner)用户dmuser
- K-means算法-机器学习入门
- C++中public&protected&private继承
- IOS经常使用的宏集合