56 lines
1.3 KiB
Plaintext
56 lines
1.3 KiB
Plaintext
prime = proc (n: int) returns (bool)
|
|
if n < 2 then return(false) end
|
|
if n//2 = 0 then return(n=2) end
|
|
if n//3 = 0 then return(n=3) end
|
|
d: int := 5
|
|
while d*d <= n do
|
|
if n//d = 0 then return(false) end
|
|
d := d+2
|
|
if n//d = 0 then return(false) end
|
|
d := d+4
|
|
end
|
|
return(true)
|
|
end prime
|
|
|
|
sum_parts = iter (l: int) yields (int)
|
|
r: int := 0
|
|
s: int := 0
|
|
while l >= 10 do
|
|
r := r + (l // 10) * 10 ** s
|
|
s := s + 1
|
|
l := l / 10
|
|
yield(l + r)
|
|
end
|
|
end sum_parts
|
|
|
|
magnanimous = proc (n: int) returns (bool)
|
|
for s: int in sum_parts(n) do
|
|
if ~prime(s) then return(false) end
|
|
end
|
|
return(true)
|
|
end magnanimous
|
|
|
|
start_up = proc ()
|
|
po: stream := stream$primary_output()
|
|
n: int := 0
|
|
i: int := 0
|
|
c: int := 0
|
|
|
|
while i <= 400 do
|
|
while ~magnanimous(n) do n := n+1 end
|
|
i := i+1
|
|
|
|
if i=1 then stream$putl(po, "1-45:") c := 0
|
|
elseif i=241 then stream$putl(po, "\n241-250:") c := 0
|
|
elseif i=391 then stream$putl(po, "391-400:") c := 0
|
|
end
|
|
|
|
if i <= 45 cor (i > 240 cand i <= 250) cor (i > 390 cand i <= 400) then
|
|
stream$putright(po, int$unparse(n), 7)
|
|
c := c+1
|
|
if c = 10 then stream$putl(po, "") c := 0 end
|
|
end
|
|
n := n+1
|
|
end
|
|
end start_up
|