本文整理汇总了Python中Euler.previous_prime方法的典型用法代码示例。如果您正苦于以下问题:Python Euler.previous_prime方法的具体用法?Python Euler.previous_prime怎么用?Python Euler.previous_prime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Euler
的用法示例。
在下文中一共展示了Euler.previous_prime方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: evaluate_prime
# 需要导入模块: import Euler [as 别名]
# 或者: from Euler import previous_prime [as 别名]
def evaluate_prime(prime):
# Evaluates a prime number and adds a key: value pair to prime_table
# with a list containing each set of pairs for that prime organized by
# number of pairs
candidate = Euler.previous_prime(prime)
answer = [] # This will be the value we return
finished = False
pairs = [prime]
while finished == False:
while candidate > 2:
if is_pair(prime, candidate) == True:
pairs.append(candidate)
candidate -= 2
if len(pairs) > 1:
answer.append((len(pairs), pairs))
candidate = Euler.previous_prime(pairs[-1])
pairs = pairs[:-1]
if len(pairs) < 2:
finished = True
if len(answer) == 0:
prime_table[prime] = False
else:
prime_table[prime] = answer
示例2: int
# 需要导入模块: import Euler [as 别名]
# 或者: from Euler import previous_prime [as 别名]
# Problem 70: Totient permutation
# candidate: 7026037
import time, Euler, math
t1 = time.clock()
limit = 10000000
root = Euler.previous_prime(int(math.sqrt(limit)))
# 3137 is the largest prime the square of which is < 10,000,000,
# Equivalent to Euler.previous_prime(int(math.sqrt(10000000)))
primes = {0: root}
large_prime_counter = 0
small_prime_counter = 0
composites = {}
large = root
small = root
while small > 2:
composite = large*small
# Deal with the case where composite is less than limit
if composite < limit:
phi = composite - (large + small - 1)
# Put the composite in the dictionary if it's a permutation
if (int("".join(sorted([x for x in str(composite)]))) ==
int("".join(sorted([x for x in str(phi)])))):
composites[composite] = [large, small, phi]
# Increase large and add it to primes if necessary