10000以内のすべての質量の和を求めます

586 ワード

# -*- coding: utf-8 -*-
 
def zhishu(num=None):
    if num is None or num == 1 or num < 0:
        return 0
     
    i = 2
    while True:
        if i == num:
            return num
        elif num % i != 0:
            i += 1
        elif num % i == 0 and num != i:
            break
         
    return 0
 
def sum_zhishu():
    sum = 0
    for i in range(10001):
        sum += zhishu(i)
    return sum
 
print sum_zhishu()

参照先:http://baike.baidu.com/link?url=TpvFbbDQbNWtalMjZIc1EZC3288x8I6ki2pyz5UJFtIHx2alz0AfMwWbG-IrnG5qDnbrlS3tBs7t4VinnJomIq