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


Python PE.isPrime方法代码示例

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


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

示例1: prob37

# 需要导入模块: import PE [as 别名]
# 或者: from PE import isPrime [as 别名]
def prob37():
	num = 0
	summ = 0
	i = 10
	while num < 11:
		# print(i)
		i += 1
		k = i
		works = True
		while k:
			if not PE.isPrime(k):
				works = False
				break
			k /= 10
		if works:	
			k = i
			while k:
				if not PE.isPrime(k):
					works = False
					break
				if k < 10:
					k = 0
				else :
					k = int(str(k)[1:])
		if works:
			print(i)
			num += 1
			summ += i
	print(summ)
开发者ID:TavorB,项目名称:ProjectEuler,代码行数:31,代码来源:prob37.py

示例2: prob46

# 需要导入模块: import PE [as 别名]
# 或者: from PE import isPrime [as 别名]
def prob46():
	n = 3
	while True:
		print(n)
		if PE.isPrime(n):
			n+=2
			continue
		found = False
		for p in range(int(math.sqrt(n)) + 1):
			if PE.isPrime(n - 2*p*p):
				found = True
				break
		if not found:
			print("soln is: " + str(n))
			return
		n+=2
开发者ID:TavorB,项目名称:ProjectEuler,代码行数:18,代码来源:prob46.py

示例3: prob7

# 需要导入模块: import PE [as 别名]
# 或者: from PE import isPrime [as 别名]
def prob7():
    numprimes = 1
    i = 2
    while numprimes != 10001:
        print(i)
        print(numprimes)
        i += 1
        if PE.isPrime(i):
            numprimes += 1

    print("and it is")
    print(i)
开发者ID:TavorB,项目名称:ProjectEuler,代码行数:14,代码来源:prob7.py

示例4: prob5

# 需要导入模块: import PE [as 别名]
# 或者: from PE import isPrime [as 别名]
def prob5():
	prod = 1
	for i in range(1,21):
		if PE.isPrime(i):
			prod *= i
		if prod % i != 0:
			k = i
			m = prod
			for c in range(1,i/2 + 1):
				if m % c == 0 and k % c == 0:
					k /= c
					m /= c
			prod *= k
	print(prod)
开发者ID:TavorB,项目名称:ProjectEuler,代码行数:16,代码来源:prob5.py

示例5: prob3

# 需要导入模块: import PE [as 别名]
# 或者: from PE import isPrime [as 别名]
def prob3():
	num = 600851475143
	curr = 1
	maxnum = 0
	while(curr < num):
		if num % curr == 0:
			num /= curr
			if PE.isPrime(num):
				maxnum = num
		print(curr)
		curr += 1
	print("and the result is")
	print(maxnum)
	return maxnum
开发者ID:TavorB,项目名称:ProjectEuler,代码行数:16,代码来源:prob3.py

示例6: prob27

# 需要导入模块: import PE [as 别名]
# 或者: from PE import isPrime [as 别名]
def prob27():
	maxcount = 0
	maxA = 0
	maxB = 0
	for a in range(-999,1000):
		for b in range(-999,1000):
			n=0
			while PE.isPrime(n*n + a*n+b):
				n +=1
			if n > maxcount:
				maxcount, maxA, maxB = n, a, b
			print(str(a) + ", " + str(b) + " : " + str(n))
	print(maxA)
	print(maxB)
	print(maxcount)
	print(maxA*maxB)
开发者ID:TavorB,项目名称:ProjectEuler,代码行数:18,代码来源:prob27.py

示例7: prob41H

# 需要导入模块: import PE [as 别名]
# 或者: from PE import isPrime [as 别名]
def prob41H(strang, arrToPut, arrIn):
	print(strang)
	# myarr = arr.copy()
	if len(strang) == len(arrToPut):
		if PE.isPrime(int(strang)):
			return int(strang)
		else:
			return 0
	l = set()
	l.add(0)
	for i in arrToPut:
		if i not in arrIn:
			newArrIn = arrIn.copy()
			newArrIn.add(i)
			# newArrToPut = arrToPut.copy()
			# newArrToPut.remove(i)
			l.add(prob41H(strang + str(i), arrToPut, newArrIn))
	print("l : " + str(l))
	return max(l)
开发者ID:TavorB,项目名称:ProjectEuler,代码行数:21,代码来源:prob41.py

示例8: range

# 需要导入模块: import PE [as 别名]
# 或者: from PE import isPrime [as 别名]
import PE

primes = 0
for i in range(2,1000000): #
	k = i
	circPrime = True
	if not PE.isPrime(i):
		continue
	for count in range(1, len(str(i))):
		k = int(str(i)[count:] + str(i)[:count])
		if not PE.isPrime(k):
			circPrime = False
			break
	if circPrime:
		primes +=1
print(primes)


开发者ID:TavorB,项目名称:ProjectEuler,代码行数:18,代码来源:prob35.py


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