Suppose we have a sequence of prime sums, where each term Pn is the sum of the first n primes.

P = (2), (2 + 3), (2 + 3 + 5), (2 + 3 + 5 + 7), (2 + 3 + 5 + 7 + 11), ...

P = 2, 5, 10, 17, 28, etc.



Further; suppose we have a sequence of composite sums, where each term Cm is the sum of the first m composites.

C = (4), (4 + 6), (4 + 6 + 8), (4 + 6 + 8 + 9), (4 + 6 + 8 + 9 + 10), ...

C = 4, 10, 18, 27, 37, etc.



Notice that the third term of P; P3 (10) is equal to the second term of C; C2 (10);



Task
 Find and display the indices (n, m) and value of at least the first 6 terms of the sequence of numbers that are both the sum of the first n primes and the first m composites.


See also
 OEIS:A007504 - Sum of the first n primes
 OEIS:A053767 - Sum of first n composite numbers
 OEIS:A294174 - Numbers that can be expressed both as the sum of first primes and as the sum of first composites


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;
            ];
        ];
]