Project Euler #77: Prime summations

  • + 0 comments

    python

    # Enter your code here. Read input from STDIN. Print output to STDOUT
    import math
    
    def check(n):
        for i in range(2, int(math.sqrt(n))+1):
            if n%i == 0:
                return False
        return True
    
    p = []
    a = [0]*1001
    for i in range(2, 1001):
        if a[i] == 0:
            if check(i):
                p.append(i)
                for j in range(2*i, 1001, i):
                    a[j] = 1
    
    n = [0]*1001
    n[0] = 1
    for n1 in p:
        for i in range(n1, 1001):
            n[i] += n[i-n1]
    
    t = int(input())
    while t > 0:
        m = int(input())
        print(n[m])
        t -= 1