Equal prime and composite sums: Difference between revisions

Added XPL0 example.
(Added XPL0 example.)
Line 200:
209,456,854,921,713 - 5,012,372nd prime sum, 19,786,181st composite sum
3,950,430,820,867,201 - 20,840,220th prime sum, 86,192,660th composite sum
</pre>
 
=={{header|XPL0}}==
<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;
];
 
int Cnt, N, M, SumP, SumC, NumP, NumC;
[Cnt:= 0;
N:= 1; M:= 1;
NumP:= 2; NumC:= 4;
SumP:= 2; SumC:= 4;
Format(8, 0);
Text(0, " sum prime composit
");
loop [if SumC > SumP then
[repeat NumP:= NumP+1 until IsPrime(NumP);
SumP:= SumP + NumP;
N:= N+1;
];
if SumP > SumC then
[repeat NumC:= NumC+1 until not IsPrime(NumC);
SumC:= SumC + NumC;
M:= M+1;
];
if SumP = SumC then
[RlOut(0, float(SumP));
RlOut(0, float(N));
RlOut(0, float(M)); CrLf(0);
Cnt:= Cnt+1;
if Cnt >= 6 then quit;
repeat NumC:= NumC+1 until not IsPrime(NumC);
SumC:= SumC + NumC;
M:= M+1;
];
];
]</lang>
 
{{out}}
<pre>
sum prime composit
10 3 2
1988 33 51
14697 80 147
83292 175 361
1503397 660 1582
18859052 2143 5699
</pre>
772

edits