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


package main
 
import (
    "fmt"
    "log"
    "rcu"
    "sort"
)
 
func ord(n int) string {
    if n < 0 {
        log.Fatal("Argument must be a non-negative integer.")
    }
    m := n % 100
    if m >= 4 && m <= 20 {
        return fmt.Sprintf("%sth", rcu.Commatize(n))
    }
    m %= 10
    suffix := "th"
    if m == 1 {
        suffix = "st"
    } else if m == 2 {
        suffix = "nd"
    } else if m == 3 {
        suffix = "rd"
    }
    return fmt.Sprintf("%s%s", rcu.Commatize(n), suffix)
}
 
func main() {
    limit := int(4 * 1e8)
    c := rcu.PrimeSieve(limit-1, true)
    var compSums []int
    var primeSums []int
    csum := 0
    psum := 0
    for i := 2; i < limit; i++ {
        if c[i] {
            csum += i
            compSums = append(compSums, csum)
        } else {
            psum += i
            primeSums = append(primeSums, psum)
        }
    }
 
    for i := 0; i < len(primeSums); i++ {
        ix := sort.SearchInts(compSums, primeSums[i])
        if ix < len(compSums) && compSums[ix] == primeSums[i] {
            cps := rcu.Commatize(primeSums[i])
            fmt.Printf("%21s - %12s prime sum, %12s composite sum\n", cps, ord(i+1), ord(ix+1))
        }
    }
}