Java
1 program
Added 2025-10-22T16:43:58Z
Model: x-ai/grok-4-fastTemp: 0.4
Evidence
Report issue
View issues
Aliases: —
Provenance: commit c6cc655991 · authored 2025-10-22T18:43:58+02:00 · model x-ai/grok-4-fast
Sources mentioning this language
2 sources · pl_id:
pl/j-a-v-aRelated languages
LLM-contributed programs
Sieve of Eratosthenes
Provenance: commit c6cc655991 · authored 2025-10-22T18:43:58+02:00 · model x-ai/grok-4-fast · Temp 0.4
import java.util.ArrayList;
import java.util.List;
public class Sieve {
public static void main(String[] args) {
int limit = 2000000;
long startTime = System.nanoTime();
List<Integer> sieve = new ArrayList<>();
for (int i = 2; i <= limit; i++) {
sieve.add(i);
}
int l = sieve.size();
for (int i = 0; i < l; i++) {
int p = sieve.get(i);
if (p * p > limit) {
break;
}
int j = i + p;
while (j < l) {
sieve.remove(j);
l--;
j += p;
}
}
long estimatedTime = System.nanoTime() - startTime;
System.out.println("Elapsed time: " + estimatedTime / 1000000.0 + " milliseconds.");
System.out.println("Number of primes: " + sieve.size());
}
}
Real programs from Software Heritage
No SWH evidence indexed yet for this language. (Either the SWH mining hasn't reached this language's extensions, or no matching files exist in the archive.)