当前位置: 首页>>代码示例>>Python>>正文


Python Euler.nextPrime方法代码示例

本文整理汇总了Python中Euler.nextPrime方法的典型用法代码示例。如果您正苦于以下问题:Python Euler.nextPrime方法的具体用法?Python Euler.nextPrime怎么用?Python Euler.nextPrime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Euler的用法示例。


在下文中一共展示了Euler.nextPrime方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: import Euler [as 别名]
# 或者: from Euler import nextPrime [as 别名]
def main(n):

	# Returns the nth prime number.
	counter = 0
	testnum = 1
	while counter < n:
		testnum = Euler.nextPrime(testnum)
		counter += 1
	return testnum
开发者ID:Grae-Drake,项目名称:Python_Euler,代码行数:11,代码来源:Problem_7.py

示例2: permutePrimes

# 需要导入模块: import Euler [as 别名]
# 或者: from Euler import nextPrime [as 别名]
def permutePrimes(prime, character):
    # Replaces each instance of character in prime with 0-9 and
    # returns a list of each resulting number that is also prime
    digits = [x for x in range(10)]
    digits = list(filter(lambda x: x != character, digits))
    answers = [prime]
    for x in digits:
        testnum = replaceDigit(prime, character, x)
        if Euler.isPrime(testnum) == True:
            if len(str(testnum)) == len(str(prime)):
                answers.append(testnum)
    return answers

counter = 0
answer = 0
permutations = []
while answer == 0:
    counter = Euler.nextPrime(counter)
    for x in range(10):
        if digitCount(counter,x) > 1:
            if len(permutePrimes(counter, x)) > 7:
                   permutations = permutePrimes(counter, x)
                   answer = permutations[0]
    
print("The answer is " + str(answer))
print("The primes are: " + str(permutations))

t2 = time.clock()
print("Execution time = " + str(t2-t1)[:5] + " seconds")
开发者ID:Grae-Drake,项目名称:Python_Euler,代码行数:31,代码来源:Problem_51.py

示例3: reversed

# 需要导入模块: import Euler [as 别名]
# 或者: from Euler import nextPrime [as 别名]
        # Problem 46: Goldbach's Other Conjecture
        
        # Find the smallest odd composite number that cannot be written as
        # the sum of a prime and twice a square.

import time, Euler
t1 = time.clock()

primes = [2,3,5,7,11]
candidate = 9
answer = 0
while True:
    if candidate == primes[-1]:
        primes.append(Euler.nextPrime(candidate))
        candidate += 2
    else:
        answer_found = False
        goldbach = False
        for prime in reversed(primes[:-1]):
            counter = 1
            while goldbach == False:
                result = (prime + (2 * (counter**2)))
                if result == candidate:
                    goldbach = True
                    candidate += 2
                elif result < candidate:
                    counter += 1
                else:
                    break
            if goldbach == True:
                break
开发者ID:Grae-Drake,项目名称:Python_Euler,代码行数:33,代码来源:Problem_46.py

示例4: int

# 需要导入模块: import Euler [as 别名]
# 或者: from Euler import nextPrime [as 别名]
    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   
        large_prime_counter +=1
        if large_prime_counter not in primes:
            primes[large_prime_counter] = Euler.nextPrime(primes[large_prime_counter-1])
        large = primes[large_prime_counter]

        # Deal with the case where composite is too big
    else:
        small_prime_counter -= 1
        large_prime_counter = small_prime_counter +1
        primes[small_prime_counter] = Euler.previous_prime(primes[small_prime_counter+1])
        small = primes[small_prime_counter]
        large = primes[large_prime_counter]

min_ratio = 3
answer = 0
for key, value in composites.items():
    n = key
    phin = value[2]
开发者ID:Grae-Drake,项目名称:Python_Euler,代码行数:33,代码来源:Problem_70.py


注:本文中的Euler.nextPrime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。