10/06/09 11:51:04 eOA+ndD5
>>204
遊びで、100,000までの素数を求めるプログラム作ったんだけど、やってるうちに
頭がウニになってきたから、これあってるかどうかチェックしてくれる??
public class sosuu {
public static void main(String[] args) {
int MAX_COUNT = 100000;
int prime = 1, prime_flag, tbl_idx = 0, max_idx = 0;
int i = 0, j = 0;
int[] prime_tbl;
max_idx = tbl_idx = 0;
prime_tbl = new int[MAX_COUNT/2];
prime_tbl[tbl_idx] = 1;
prime_tbl[++max_idx] = 2;
for ( i = 3; i <= MAX_COUNT; i++ ) {
prime_flag = 1;
for ( tbl_idx = 0; tbl_idx < max_idx; tbl_idx++ ) {
if ( prime_tbl[tbl_idx] == 1 ) continue;
if ( i % prime_tbl[tbl_idx] == 0 ) {
prime_flag = 0;
break;
}
}
if ( prime_flag == 1 ) prime_tbl[++max_idx] = i;
}
for ( tbl_idx = 0; tbl_idx <= max_idx; tbl_idx++ )
System.out.println(prime_tbl[tbl_idx]);
}