您的位置:首页 > 其它

Project Euler 10 Summation of primes

2013-10-08 13:40 363 查看
Project Euler 10 Summation of primes

#!/usr/bin/env python
#-*- coding: utf-8 -*-
'''
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
'''
from math import *

def isPrime(num):
if num < 2:
return False
if num == 2:
return True
if num%2 == 0:
return False

i = 3
while( i*i <= num):
if num%i == 0:
return False
i += 2
return True

i=2
s=0
while i<=2000000:
if isPrime(i)==True:
s+=i
print i,s
i+=1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: