Created
October 24, 2015 10:45
-
-
Save iiogmgo/d6e727c8cc512dc7f66b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from math import sqrt | |
def euler_10(num): | |
""" | |
변수 num 이하의 소수의 합을 구합니다 | |
""" | |
prime_sum = 0 | |
for_x = 2 | |
while for_x <= num: | |
flag = 0 | |
for y in range(2, int(sqrt(for_x)+1)): | |
if for_x%y == 0: | |
flag += 1 | |
break | |
if flag == 0: | |
prime_sum += for_x | |
for_x = for_x+1 if for_x%2==0 else for_x+2 | |
print(num, '이하의 소수의 합 : ', prime_sum) | |
if __name__== '__main__': | |
t = time.time() | |
euler_10(2000000) | |
print('python Elapsed %.02f' % (time.time()-t)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
도움이 되었습니다. 감사합니다. 배움에는 끝이없네요