[Swust OJ 1125]--See also gcd (number theory, Prime Table storage factor)

Source: Internet
Author: User
Tags greatest common divisor

Title Link: http://acm.swust.edu.cn/problem/1125/

Time limit (ms): $ Memory Limit (KB): 65535 description Hart 13 was recently studying number theory, and then he had a low IQ and could not understand it. No, he's not going to have a problem again. Test instructions is very simple:

There are n numbers to find the maximum value of 22 greatest common divisor in these numbers. You must help him to solve the problem.

Input

Multiple sets of inputs, about 25 groups, until the end of the file.
Each group of data accounted for 2 rows, the number of first behavior n,2<=n<=100000
The second line is the corresponding n number, A1 to an,1<=ai<=100000

Output

Output the answer to the question, one row for each set of outputs.

Sample Input

41 2 3 4

Sample Output

2


Sorry, for OJ reasons, please use \ r \ n problem-solving ideas: The same table problems, all the data are processed, using the vector container to all the number of factors all storage, statistics all the input number of each factor of the number of coverage because it is to find the largest gcd, from the input number of the upper limit (100000) to look backwards, if a factor is covered two times and above, then this factor is the answer ~ ~ ~The code is as follows:
1#include <iostream>2#include <vector>3#include <cstring>4 using namespacestd;5 #defineMax 1000006vector<int>Mpt[max];7 voidinit () {8      for(inti =1; I <= Max; i++)9      for(intj =1; J*i <= Max; J + +)Tenmpt[i*J].push_back (i); One } A intMain () { -     intDp[max], I, CNT, x, N; - init (); the      while(Cin >>N) { -Memset (DP,0,sizeof(DP)); -          while(n--){ -CIN >>x; +CNT =mpt[x].size (); -              for(i =0; I < CNT; i++) +dp[mpt[x][i]]++; A         } at          for(i = max; i; i--){ -             if(dp[i]>1) -                  Break; -         } -cout << i <<"\ r \ n"; -     } in     return 0; -}
View Code

     

[Swust OJ 1125]--See also gcd (number theory, Prime Table storage factor)

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.