Max FactorTime
limit:1000MS
Memory Limit:32768KB
64bit IO Format:%i64d &%i64 U
Description
To improve the organization of he farm, Farmer John labels each of its n (1 <= n <= 5,000) cows with a distinct ser Ial number in the range 1..20,000. Unfortunately, he is unaware, the cows interpret some serial numbers as better than others. In particular, a cow whose serial number have the highest prime factor enjoys the highest social standing among all the oth ER cows.
(Recall that a prime number is just a number, the has no divisors except for 1 and itself. The number 7 is prime while the number 6, being divisible by 2 and 3, was not).
Given a set of n (1 <= n <= 5,000) serial numbers in the range 1..20,000, determine the one, and the largest PRI Me factor.
Input
* Line 1: A single integer, N
* Lines 2..n+1:the serial numbers to being tested, one per line
Output
* Line 1:the integers with the largest prime factor. If there is more than one, the output of the one that is appears earliest in the input file.
Sample Input
436384042
Sample Output
38
Compare Water XJB do
The new style is good, and then it's written.
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include < queue> #include <vector> #include <iomanip> #include <math.h> #include <map>using namespace STD; #define FIN freopen ("Input.txt", "R", stdin); #define INF 0x3f3f3f3f#define Lson l,m,rt<<1# Define Rson m+1,r,rt<<1|1typedef long long ll;const int maxn=20005;int p[maxn];int main () { //fin p[1 ]=1; int cou=0; for (int i=2; i<=20005; i++) { if (p[i]==0) { cou++; for (int j=i; j<=20005; j=j+i) { p[j]=cou; } } } int n; while (~SCANF ("%d", &n)) { int ans=0,pos; int x; for (int i=1;i<=n;i++) { scanf ("%d", &x); if (P[x]>ans) {ans=p[x];p os=x;} } printf ("%d\n", POS); }}
HDU 2710 Max Factor number theory (water