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


Python Euler.isPrime方法代码示例

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


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

示例1: permutePrimes

# 需要导入模块: import Euler [as 别名]
# 或者: from Euler import isPrime [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
开发者ID:Grae-Drake,项目名称:Python_Euler,代码行数:14,代码来源:Problem_51.py

示例2: main

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

	# Iterates through each number less than limit testing for primeness.
	# Counter is multiplied by each prime number for the a number of times
	# equal to the greatest number of times that prime divides a number less
	# than or equal to the limit.  For example, 2 divides 8 3 times (8 = 2*2*2),
	# so when limit == 10 counter is multiplied by 2^3.
	counter = 1
	for x in range(2, limit+1):
		if Euler.isPrime(x):
			counter *= (x ** math.floor(math.log(limit, x)))
	return counter
开发者ID:Grae-Drake,项目名称:Python_Euler,代码行数:14,代码来源:Problem_5.py

示例3: naiveResilience

# 需要导入模块: import Euler [as 别名]
# 或者: from Euler import isPrime [as 别名]
def naiveResilience(num):
    if(num==1): return 0/num
    if(Euler.isPrime(num,Euler.currPrimes)): return (num-1)/num
    count = 1
    for i in range(2,num):
        hit = False
        b = math.sqrt(num)
        for p in Euler.currPrimes:
            if(p>b): break
            if(i%p==0 and num%p==0):
                hit = True
                break
        if(not hit): count+=1
    return count/num
开发者ID:msimmara,项目名称:NoSpeulers,代码行数:16,代码来源:Euler2.py

示例4: range

# 需要导入模块: import Euler [as 别名]
# 或者: from Euler import isPrime [as 别名]
        # Problem 58: Spiral primes

import time
import Euler

t1 = time.clock()

diagonal = 1
primes = []
non_primes = [1]
side_length = 3
ratio = 1

while ratio > 1/10:        # Change to: while found = False
    for x in range(4):
        diagonal += side_length - 1
        if Euler.isPrime(diagonal) == True:
            primes.append(diagonal)
        else:
            non_primes.append(diagonal)
    ratio = len(primes) / (len(primes) + len(non_primes))
    side_length += 2

t2 = time.clock()

print("Side length = ", side_length - 2)
print(str(t2-t1)[:9])
开发者ID:Grae-Drake,项目名称:Python_Euler,代码行数:29,代码来源:Problem_58.py

示例5: is_pair

# 需要导入模块: import Euler [as 别名]
# 或者: from Euler import isPrime [as 别名]
def is_pair(x,y):
    # Returns True if xy and yx are each prime, else returns False
    
    test1 = int(str(x) + str(y))
    test2 = int(str(y) + str(x))
    return Euler.isPrime(test1) == True and Euler.isPrime(test2) == True        
开发者ID:Grae-Drake,项目名称:Python_Euler,代码行数:8,代码来源:Problem_60.py

示例6: enumerate

# 需要导入模块: import Euler [as 别名]
# 或者: from Euler import isPrime [as 别名]
        # Problem 50: Consecutive Prime Sum
import time
t1 = time.clock()
import Euler
limit = 4000
primes = [x for x in Euler.primeSieve(limit)]
answer = [(0,[])]
for x, prime1 in enumerate(primes):
    startprime = x
    sequence = []
    counter = 0
    for y, prime2 in enumerate(primes):
        if y >= x:
            counter += prime2
            if Euler.isPrime(counter) == True:
                if counter < 1000000:
                    sequentials = [x for x in primes[x:y+1]]
                    if len(answer[0][1]) < len(sequentials):
                        answer[0] = ((counter, sequentials))

print("Prime = " + str(answer[0][0]) + " ; Length of sequence: " + str(len(answer[0][1])))
print("Sequence start = " + str(answer[0][1][0]) + " ; Sequence end = " + str(answer[0][1][-1]))
t2 = time.clock()
print("Runtime = " + str(t2-t1)[:4] + " seconds")
开发者ID:Grae-Drake,项目名称:Python_Euler,代码行数:26,代码来源:Problem_50.py


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