Calmo numbers: Difference between revisions

Added XPL0 example.
m (→‎{{header|ALGOL 68}}: correct comment)
(Added XPL0 example.)
Line 337:
957 [3, 11, 29, 33, 87, 319] [43, 439]
</pre>
 
=={{header|XPL0}}==
<syntaxhighlight lang "XPL0">func IsPrime(N); \Return 'true' if N is prime
int N, I;
[if N <= 2 then return N = 2;
if (N&1) = 0 then \even >2\ return false;
for I:= 3 to sqrt(N) do
[if rem(N/I) = 0 then return false;
I:= I+1;
];
return true;
];
 
func IsCalmo(N); \Return 'true' if N is a Calmo number
int N, Limit, Count, SumD, SumQ, K, D, Q;
[Limit:= sqrt(N);
Count:= 0; SumD:= 0; SumQ:= 0; K:= 0;
D:= 2;
repeat Q:= N/D;
if rem(0) = 0 then
[Count:= Count+1;
SumD:= SumD+D;
SumQ:= SumQ+Q;
if Count = 3 then
[K:= K+3;
if not IsPrime(SumD) then return false;
if not IsPrime(SumQ) then return false;
Count:= 0; SumD:= 0; SumQ:= 0;
];
];
D:= D+1;
until D >= Limit;
if Count # 0 or K = 0 then return false;
return true;
];
 
int N;
[for N:= 1 to 1000-1 do
if IsCalmo(N) then
[IntOut(0, N); ChOut(0, ^ )];
]</syntaxhighlight>
{{out}}
<pre>
165 273 385 399 561 595 665 715 957 </pre>
291

edits