27 lines
639 B
Text
27 lines
639 B
Text
local int = require "int"
|
|
local fmt = require "fmt"
|
|
|
|
local function is_curzon(n, k)
|
|
local r = k * n
|
|
return int.modpow(k, n, r+1) == r
|
|
end
|
|
|
|
for k = 2, 10, 2 do
|
|
print($"The first 50 Curzon numbers with base {k}:")
|
|
local n = 1
|
|
local count = 0
|
|
while count < 50 do
|
|
if is_curzon(n, k) then
|
|
fmt.write("%4d ", n)
|
|
count += 1
|
|
if count % 10 == 0 then print() end
|
|
end
|
|
n += 1
|
|
end
|
|
while true do
|
|
if is_curzon(n, k) then count += 1 end
|
|
if count == 1000 then break end
|
|
n += 1
|
|
end
|
|
fmt.print("\nOne thousandth: %s\n", fmt.int(n))
|
|
end
|