We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital and is also prime.
What is the largest n-digit pandigital prime that exists?
全数字的素数
如果一个n位数恰好使用了1至n每个数字各一次,我们就称其为全数字的。例如,2143就是一个4位全数字数,同时它恰好也是一个素数。
最大的全数字的素数是多少?
import math
import itertools
def is_Prime(number):
if number < 2:
return False
for x in range(2, int(math.sqrt(number)) + 1):
if number % x == 0:
return False
return True
for level in reversed(range(1, 10)):
numbers = [i for i in reversed(range(1, level + 1))]
b = False
for i in list(itertools.permutations(numbers, level)):
number = eval("".join(str(x) for x in i))
if is_Prime(number):
print number
b = True
break
if b:
break
算出那个最大的数[Finished in 68.9s],貌似不太符合要求,不过一下子没想出更好的办法……
自从Dyn被DDOS攻击以后,在家里上github就各种不顺溜,晚上基本是没希望了,发现早上还勉强
最近工作也各种忙,要各种刷不了题目了