Search for prime factor

Source: Internet
Author: User

Description

N numbers are given. Try to find the number with the largest quality factor.

Input Format: InputFormat

The first line is an integer N, indicating the number of digits.
In the next N rows, each row has an integer A_ I, indicating the given number.

Output Format: OutputFormat

An integer that represents the number with the largest prime factor.

Data range and comment Hint

N <= 5000, A_ I <= 20000
Example 38 and 12
38 = 19*2
12 = 2*3*3
The maximum value of 38 is 19.
The maximum value of 12 is 3.
Therefore, the data output is 38.



Sample input:

4
36
38
40
42

Sample output:

38


Code:

# Include
# Include
Int a [5010];
Int zhi (int n)
{
If (n = 2) return 1;
For (int I = 2; I <= sqrt (n); I ++)
If (n % I = 0) return 0;
Return 1;
}
Int yin (int n)
{
Int c;
If (zhi (n) return n;
For (int I = 2; I If (n % I = 0 & zhi (I) c = I;
Return c;
}
Int main (int argc, char * argv [])
{
Int n, I, max, l;
Scanf ("% d", & n );
For (I = 0; I Scanf ("% d", & a [I]);
Max = 1;
For (I = 0; I If (yin (a [I])> = max ){
Max = yin (a [I]); l = a [I];
}
Printf ("% d \ n", l );
Return 0;
}

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.