首页 > 代码库 > WeChall_Prime Factory (Training, Math)
WeChall_Prime Factory (Training, Math)
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
解题:
素数打表,依次从小到达剔除素数的倍数的数。
def allsum(x): sum = 0 while x: sum += x%10 x //= 10 return sumtotal = 2000000prime = []a = [1 for i in range(total)]for i in range(2,total): if a[i]: prime.append(i) time = 2 while 1: num = time*i if num >= total: break a[num] = 0 time += 1find = 0for i in range(1000000,total): if i in prime and allsum(i) in prime: print(i) find += 1 if find == 2: break
WeChall_Prime Factory (Training, Math)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。