Your task is simple:
Find the first two primes above 1 million, whose separate digit sums are also prime.
As example take 23, which is a prime whose digit sum, 5, is also prime.
The solution is the concatination of the two numbers,
Example: If the first number is 1,234,567
and the second is 8,765,432,
your solution is 12345678765432
你的任务很简单:
找出 100 万以上的前两个素数,它们各自的数字和也是素数。
以 23 为例,它是一个素数,其数字和 5 也是素数。
解决方案是将两个数字连接起来,
例如:如果第一个数字是 1,234,567
,第二个数字是 8,765,432,则
您的解决方案是 12345678765432
def primess(num): for i in range(2,num):#判断在num之前的数能不能把num整除 if(num % i == 0): return 1 ##不为素数 else: return 0 ##为素数 def wet(a): sum = 0 for i in range(0,len(a)): sum = sum + int(a[i]) return sum while True: for i in range(1000000,10000000): num=i if primess(num)==0: a=str(i) num=int(wet(a)) if primess(num)==0: print(i)