mirror of
https://github.com/jlengrand/project_euler.git
synced 2026-03-10 08:41:20 +00:00
38 lines
1.0 KiB
Python
Executable File
38 lines
1.0 KiB
Python
Executable File
#!/usr/bin/env python
|
|
"""
|
|
##---
|
|
# jlengrand
|
|
#Created on : Fri Jan 13 11:42:09 CET 2012
|
|
#
|
|
# DESCRIPTION : Solves problem 10 of Project Euler
|
|
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
|
|
Find the sum of all the primes below two million.
|
|
##---
|
|
"""
|
|
def sum_primes(value):
|
|
"""
|
|
Returns the sum of prime number below value
|
|
"""
|
|
prime_list = [2]
|
|
curr_val = 3
|
|
ptr = False
|
|
while( curr_val <= value):
|
|
while(not ptr):
|
|
for primes in prime_list:
|
|
if primes < pow(curr_val, 0.5):
|
|
if (curr_val % primes == 0):
|
|
ptr = True # multiple of at least one value
|
|
if not ptr:
|
|
prime_list.append(curr_val)
|
|
print "%d%% / %d" % (((prime_list[-1] / float(value)) * 100), prime_list[-1])
|
|
ptr = True
|
|
|
|
curr_val +=1
|
|
ptr = False
|
|
|
|
#print prime_list
|
|
return sum(prime_list)
|
|
|
|
if __name__ == '__main__':
|
|
print "Answer : %d" % (sum_primes(20000))
|