Wechall_prime Factory (Training, Math)

Source: Internet
Author: User

Your task is simple:
Find the first and the primes above 1 million, whose separate digit sums are also prime.
As example take, which are a prime whose digit sum, 5, is also prime.
The solution is the concatination of the numbers,
Example:if The first number is 1,234,567
And the second is 8,765,432,
Your solution is 12345678765432

Solving:

The number of multiples of prime numbers hitting the table, in turn from small to eliminated primes.

defallsum (x): Sum=0 whileX:sum+ = X%10x= 10returnSumTotal= 2000000Prime=[]a= [1 forIinchrange (total)] forIinchRange (2, total):ifA[i]: prime.append (i) time= 2 while1: Num= time*IifNum >=Total: BreakA[num]=0 Time+ = 1Find=0 forIinchRange (1000000, total):ifIinchPrime andAllsum (i)inchPrime:Print(i) Find+ = 1iffind = = 2:             Break

Wechall_prime Factory (Training, Math)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.