Prime numbers p for which the sum of primes less than or equal to p is prime: Difference between revisions
Prime numbers p for which the sum of primes less than or equal to p is prime (view source)
Revision as of 20:41, 7 July 2021
, 2 years agoAdded XPL0 example.
m (changed "prime numbers" ---> "primes", added whitespace.) |
(Added XPL0 example.) |
||
Line 186:
Found 21 such primes.
</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;
];
int Count, N, M, Sum;
[Count:= 0;
for N:= 2 to 1000-1 do
if IsPrime(N) then
[Sum:= 0;
for M:= 2 to N do
if IsPrime(M) then
Sum:= Sum + M;
if IsPrime(Sum) 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, " such numbers found below 1000.
");
]</lang>
{{out}}
<pre>
2 3 7 13 37 43 281 311 503 541
557 593 619 673 683 733 743 839 881 929
953
21 such numbers found below 1000.
</pre>
|