本文整理汇总了Python中Euler.sieve_erat方法的典型用法代码示例。如果您正苦于以下问题:Python Euler.sieve_erat方法的具体用法?Python Euler.sieve_erat怎么用?Python Euler.sieve_erat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Euler
的用法示例。
在下文中一共展示了Euler.sieve_erat方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: len
# 需要导入模块: import Euler [as 别名]
# 或者: from Euler import sieve_erat [as 别名]
#7 + 3
#5 + 5
#5 + 3 + 2
#3 + 3 + 2 + 2
#2 + 2 + 2 + 2 + 2
#
#What is the first value which can be written as the sum of primes in over five
#thousand different ways?
#
#Variation of problems 31, 76
import time
import Euler as E
N = 5000 #combinations
primes = E.sieve_erat(1000) #set of primes to be summed
m = len(primes)
sol = 1 #values to be generated as sum of primes
start = time.time()
#dynamic solution
while True:
ways = [1] + [0] * sol
for p in primes:
for j in range(p, sol + 1):
ways[j] += ways[j - p]
if ways[sol] > N:
print sol
break