Summation of primes: Difference between revisions

Added XPL0 example.
(Added XPL0 example.)
Line 235:
<pre>
The sum of all primes below 2 million is 142,913,828,922.
</pre>
 
=={{header|XPL0}}==
Takes 3.7 seconds on Pi4.
<lang XPL0>func IsPrime(N); \Return 'true' if N is a prime number >= 3
int N, I;
[if (N&1) = 0 then return false; \N is even
for I:= 3 to sqrt(N) do
[if rem(N/I) = 0 then return false;
I:= I+1; \step by 2 (=1+1)
];
return true;
];
 
real Sum; \provides 15 decimal digits
int N; \provides 9 decimal digits
[Sum:= 2.; \2 is prime
for N:= 3 to 2_000_000 do
if IsPrime(N) then Sum:= Sum + float(N);
Format(1, 0); \don't show places after decimal point
RlOut(0, Sum);
]</lang>
 
{{out}}
<pre>
142913828922
</pre>
772

edits