Max Factor HDU-2710

Source: Internet
Author: User

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 ;}

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.