WeChall_Prime Factory (Training, Math)
Posted 冷暖知不知
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 sum total = 2000000 prime = [] 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 += 1 find = 0 for 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)的主要内容,如果未能解决你的问题,请参考以下文章
factory源码分析——uvm_default_factory
spring 之 factory-bean & factory-method
Django formset_factory vs modelformset_factory vs inlineformset_factory