Topcoder SRM 643 Div1 250<peter_pan>

Source: Internet
Author: User

Topcoder SRM 643 DIV1 250

Problem

Give an integer n, and then give a Vector<long long>v; n can be expressed as a product of several prime numbers, N=P0*P1*P2*......*PN, we assume that the P0,P1,..., PN is monotonic, then v is stored in the subscript is an even number of N of the mass factor p0,p2,p4,..., p (2k). Now asked to write a program that returns a Vector<long long>ans; Ans Stores the p0,p1,p2,..., PN.

Limits

Time Limit (MS): 2000

Memory Limit (MB): 256

N: [2,10^18]

Solution

n is continuously removed from the number of V (N/=v[i];) and a new n is obtained, which is recorded as N1. The N1 is then decomposed factorization. In [1,10^6] scanning, will N1 decomposition, to obtain a new N1, recorded as N2. If the N2 is not 1, it can be proved that N2 must be a prime number, add ans. The ANS is sorted and returned.

More

Worry about the following scenario, N=2*P1,P1 is a prime number with a level of 1e17. So in the decomposition of factorization, you can not use O (n^0.5) algorithm, otherwise it will time out, and used in [1,10^6] scan to decompose N1. The following shows that N2 must be a prime number, considering the mass factor of n , there are up to two qualitative factors PI,PJ will be greater than 10^6 (the other mass factor is less than or equal to 10^6, then in the [1,10^6] scanning to decompose N1 has been found). Assuming there are two qualitative factors pi,pj greater than 10^6, then because the given V is ordered, PI,PJ is the largest of all factorization, so PI,PJ must have and only one appears in V, so n2=pi or pj,n2 is prime; assuming there is only one pi greater than 10^6, then n2= PI,N2 is a prime number.

Complexity

Time Complexity:o (1e6)

Memory Complexity:very Small

Source

Topcoder SRM 643 DIV1 250

Code

Topcoder SRM 643 Div1 from My Github

Topcoder SRM 643 Div1 250<peter_pan>

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.