100 followers problem

Sum of the first 1000 prime numbers


The answer is 3682913.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

4 solutions

Pranjal Jain
Mar 22, 2015
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
def isPrime(x):
    """Returns 1 if the number is prime, otherwise 0"""
    if x<2:
        return 0
    if floor(x)!=x:
        return 0
    for i in range(2,x):
        if x%i==0:
            return 0
    return 1
i=1
n=0
a=[]
while(n<1000):
    if isPrime(i):
        a.append(i)
        n+=1
    i+=1
sum(a)

@gundu cat Is there any number theory solution? I am moving this to Computer Science.

Pranjal Jain - 6 years, 2 months ago
Swapnil Das
May 13, 2015

Wolfram Alpha result! Link

Just Google search :p

Brock Brown
Mar 23, 2015

Python 2.7:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
from math import sqrt
def prime(n):
    if n <= 1:
        return False
    for test in xrange(2, int(sqrt(n))+1):
        if n % test == 0:
            return False
    return True
total = 0
count = 0
n = 0
while count < 1000:
    n += 1
    if prime(n):
        total += n
        count += 1
print "Answer:", total

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...