HDU 2710 Max Factor (find the maximum prime number)

Source: Internet
Author: User

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2710


Problem descriptionto improve the organization of his farm, Farmer John labels each of his n (1 <= n <= 5,000) cows with a distinct serial number in the range 1 .. 20,000. unfortunately, he is unaware that the cows interpret some serial numbers as better than others. in particle, a cow whose serial number has the highest prime factor enjoys the highest social standing among all the other cows.

(Recall that a prime number is just a number that has no divisors should t for 1 and itself. the number 7 is prime while the number 6, being divisible by 2 and 3, is not ).

Given a set of N (1 <= n <= 5,000) serial numbers in the range 1 .. 20,000, determine the one that has the largest prime factor.
 
Input * Line 1: A single integer, n

* Lines 2. n + 1: the serial numbers to be tested, one per line
Output * Line 1: The integer with the largest prime factor. If there are more than one, output the one that appears earliest in the input file.
Sample Input
436384042
 
Sample output
38
 
Sourceusaco 2005 October Bronze


Question:
Calculate the number of prime numbers containing the maximum prime numbers, for example, 36 38 40 42, that is, the maximum Prime Number of 19 38, which is also the maximum Prime Number of 4.

Therefore, the output contains 38 of the maximum prime numbers. In addition, if there are multiple numbers at the end of the question, the first number must be output.

Ideas:

Name all the prime numbers in the table and search for them!

The Code is as follows:

# Include <cstdio> # include <cstring> const int maxn = 20017; int s [maxn]; int main () {int n, m; memset (S, 0, sizeof (s); s [1] = 1; // This question 1 is also a prime number for (INT I = 2; I <maxn; I ++) // filter prime numbers in all ranges {If (s [I] = 0) // For (Int J = I; j <maxn; J + = I) {s [J] = I ;}} while (~ Scanf ("% d", & N) {int ans; int Maxx =-1; for (INT I = 0; I <n; I ++) {scanf ("% d", & M); If (s [m]> Maxx) {Maxx = s [m]; ans = m ;}} printf ("% d \ n", ANS);} 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.