Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2710
Given n numbers, find the number containing the maximum prime factor.
TwoCode: Your own disgusting code
#include
# include
# include
#include
using namespace STD; int P [20010], Max [20005]; inline int CAL (int x) {for (INT I = X/2; I> = 1; -- I) {If (! P [x]) return X; If (! P [I] & X % I = 0) return I ;}} inline void getint (Int & X) {char C; while (C = getchar (), c <'0' | C> '9'); X = C-'0'; while (C = getchar (), c> = '0' & C <= '9') x = x * 10 + C-'0'; return;} int main () {int N; for (INT I = 4; I <= 20005; I + = 2) {P [I] = 1 ;}for (INT I = 3; I <= 20005; ++ I) {If (! P [I]) {int K = 2 * I; for (Int J = I * I; j <= 20005; j + = K) P [J] = 1 ;}}for (INT I = 1; I <= 20000; ++ I) // This process is complicated {max [I] = CAL (I);} while (scanf ("% d", & n) = 1) {int max =-1, num, ans; For (INT I = 0; I
Code for new ideas:
# Include <cstring> # include <cstdlib> # include <cstdio> # include <cmath> using namespace STD; int data [20005]; int main () {int N; for (INT I = 2; I <= 20000; ++ I) {If (! Data [I]) {for (Int J = 1; I * j <= 20000; ++ J) data [I * j] = I ;}} while (scanf ("% d", & n) = 1) {int max =-1, ans; For (INT I = 0; I <n; ++ I) {int C; scanf ("% d", & C); If (max <data [c]) {ans = C; max = data [c] ;}} printf ("% d \ n", ANS);} return 0 ;}