Additive primes: Difference between revisions

Content deleted Content added
Chunes (talk | contribs)
Add Seed7
Loren (talk | contribs)
Added XPL0 example.
Line 1,037: Line 1,037:


54 additive primes found.
54 additive primes found.
</pre>

=={{header|XPL0}}==
<lang XPL0>func IsPrime(N); \Return 'true' if N is a prime number
int N, I;
[if N <= 1 then return false;
for I:= 2 to sqrt(N) do
if rem(N/I) = 0 then return false;
return true;
];

func SumDigits(N); \Return the sum of the digits in N
int N, Sum;
[Sum:= 0;
repeat N:= N/10;
Sum:= Sum + rem(0);
until N=0;
return Sum;
];

int Count, N;
[Count:= 0;
for N:= 0 to 500-1 do
if IsPrime(N) & IsPrime(SumDigits(N)) then
[IntOut(0, N);
Count:= Count+1;
if rem(Count/10) = 0 then CrLf(0) else ChOut(0, 9\tab\);
];
CrLf(0);
IntOut(0, Count);
Text(0, " additive primes found below 500.
");
]</lang>

{{out}}
<pre>
2 3 5 7 11 23 29 41 43 47
61 67 83 89 101 113 131 137 139 151
157 173 179 191 193 197 199 223 227 229
241 263 269 281 283 311 313 317 331 337
353 359 373 379 397 401 409 421 443 449
461 463 467 487
54 additive primes found below 500.
</pre>
</pre>