mirror of
https://github.com/MartinThoma/LaTeX-examples.git
synced 2025-04-26 06:48:04 +02:00
misc
This commit is contained in:
parent
1cc20da665
commit
b18561fc54
19 changed files with 197 additions and 0 deletions
|
@ -0,0 +1,27 @@
|
|||
import java.util.Arrays;
|
||||
|
||||
public class SieveOfErasthostenes {
|
||||
|
||||
public static boolean[] sieveIt(int n) {
|
||||
boolean[] sieve = new boolean[n+1];
|
||||
Arrays.fill(sieve, true);
|
||||
sieve[0] = false;
|
||||
sieve[1] = false;
|
||||
for (int i=2; i <= Math.sqrt(n); i++) {
|
||||
if (sieve[i]) {
|
||||
for (int c = i*i; c <= n; c += i) {
|
||||
sieve[c] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return sieve;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
final int n = 100_000_000;
|
||||
final long startTime = System.currentTimeMillis();
|
||||
sieveIt(n);
|
||||
final long endTime = System.currentTimeMillis();
|
||||
System.out.println(endTime-startTime);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue