main() {
print(primesLessThan(15));
}
// Computes primes less than [n] using the Sieve of Eratosthenes.
primesLessThan(n) {
var l = new List.generate(n, (i) => i);
for (int i = 2; i * i < n; i++)
if (l[i] != null)
for (int j = i * i; j < n; j += i)
l[j] = null;
return l.skip(2).where((i) => i != null);
}
|
Perf
Output