Junk

Junk Git Source Tree

Root/lua/sieve.lua

1function sieve(n)
2 if not n then n = 10000000 end
3 local is_prime = {}
4
5 for i = 1, n do
6 is_prime[i] = 1 ~= i
7 end
8
9 for i = 2, math.floor(math.sqrt(n)) do
10 if is_prime[i] then
11 for j = i*i, n, i do
12 is_prime[j] = false
13 end
14 end
15 end
16
17 return is_prime
18end
19
20local t = sieve(arg[1])
21
22for n = 1, #t do
23 if t[n] then print(n) end
24end

Archive Download this file

Branches