local fmt = require "fmt" local primes = {3, 5} local cutoff = 200 local bigone = 100_000 local cubans = {} local big_cuban = "" local c = 0 local show_each = true local u = 0 local v = 1 for i = 1, (1 << 20) - 1 do local found = false u += 6 v += u local mx = math.floor(math.sqrt(v)) for primes as item do if item > mx then break end if v % item == 0 then found = true break end end if !found then c += 1 if show_each then local z = primes:back() while z <= v - 2 do z += 2 local fnd = false for primes as item do if item > mx then break end if z % item == 0 then fnd = true break end end if !fnd then primes:insert(z) end end primes:insert(v) cubans:insert(fmt.int(v)) if c == cutoff then show_each = false end end if c == bigone then big_cuban = fmt.int(v) break end end end print("The first 200 cuban primes are:-") fmt.tprint("%10s", cubans:slice(1, 200), 10) print($"\nThe 100,000th cuban prime is {big_cuban}")