"""
Summarize primes
http://www.rosettacode.org/wiki/Summarize_primes
"""

import itertools
import sympy


def get_subseq(n: int):
    # prime list [2, n)
    primes = list(sympy.primerange(n))
    # cummulative sum list of primes
    cum_primes = list(itertools.accumulate(primes))
    # Internally primes exntends to [2, sum of primes in range [2, n)]
    # to see if sum of items in primes is also prime
    primes = primes + list(sympy.primerange(n, sum(primes)))

    subseqs = []
    for idx, val in enumerate(cum_primes):
        if val in primes:  # if cumulative sum is also prime
            # (length of subseq, last prime num in subseq, sum of subseq)
            subseq = (idx + 1, primes[idx], val)
            subseqs.append(subseq)

    return subseqs


def main():
    rst = get_subseq(1000)
    print("prime   last  prime")
    print("count  prime    sum")
    for item in rst:
        sb = f"{item[0]:5d}  {item[1]:5d}  {item[2]:5d}"
        print(sb)


if __name__ == "__main__":
    main()
