现在的位置: 首页 > 综合 > 正文

杂题

2013年01月15日 ⁄ 综合 ⁄ 共 1918字 ⁄ 字号 评论关闭


Andrew has just made a breakthrough in sociology: he realized how to predict whether two persons will be good friends or not. It turns out that each person
has an inner 
friendship number (a
positive integer). And the 
quality of friendship between
two persons is equal to the greatest common divisor of their friendship number. That means there are 
primepeople
(with a prime friendship number) who just can't find a good friend, and
Wait,
this is irrelevant to this problem. You are given a list of friendship numbers for several people. Find the highest possible quality of friendship among all pairs of given people. 

Input

The first line of the input file contains an integer n () —
the number of people to process. The next 
n lines
contain one integer each, between 1 and 
(inclusive),
the friendship numbers of the given people. All given friendship numbers are distinct. 

Output

Output one integer — the highest possible quality of friendship. In other words, output the greatest greatest common divisor among all pairs of given
friendship numbers. 

Example(s)
sample input
sample output
4
9
15
25
16
5
/*
 * Author:  *******
 * Created Time:  2013/8/17 18:57:51
 * File Name: C.cpp
 * solve: C.cpp
 */
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<stack>
#include<set>
#include<iostream>
#include<vector>
#include<queue>

using namespace std;
#define sz(v) ((int)(v).size())
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repf(i, a, b) for (int i = (a); i <= (b); ++i)
#define repd(i, a, b) for (int i = (a); i >= (b); --i)
#define clr(x) memset(x,0,sizeof(x))
#define clrs( x , y ) memset(x,y,sizeof(x))
#define out(x) printf(#x" %d\n", x)
#define sqr(x) ((x) * (x))
typedef int LL;

const int INF = 1000000000;
const double eps = 1e-8;
const int maxn = 1000010;

int sgn(const double &x) {  return (x > eps) - (x < -eps); }

int used[maxn];

int main() 
{
    //freopen("in.txt","r",stdin);
    int n;
    scanf("%d",&n);
    clr(used);
    
    int maxi = 0;
    
    for(int i = 0;i<n;++i)
    {
        int a;
        scanf("%d",&a);
        used[a] = 1;
        maxi = max(maxi,a);
    }
     
    int ans = 0;
    for(int i = maxi;i>=1;--i)
    {
        int num = 0;
        for(int j = i;j<=maxi;j+=i)
        {
            if(used[j])
            {
                num++;
                if(num>1)
                {
                    ans = i;
                    goto here;
                }
            }
        }
    }
here:
    cout<<ans<<endl;
    
    return 0;
}


抱歉!评论已关闭.