51nod_1179_计算N个数之间两两之间GCD的最大值

来源:互联网 发布:nginx配置stream 编辑:程序博客网 时间:2024/06/05 14:00

这里写图片描述

#include<iostream>#include<cstdio>using namespace std;const int maxs = 1e6 + 10;int D[maxs];int main(){    int n;    cin >> n;    long long x,themax = 0;    for (int i = 0;i < n;i++)    {        scanf("%lld", &x);        D[x]++;        if (x > themax)        {            themax = x;        }    }    int ans = -1;    for (int i = themax;i > 0;i--)    {        int sum = 0;        for (int j = i;j <= themax&&sum<2;j += i)        {            sum += D[j];        }if (sum == 2)        {            ans = i;            break;        }    }    cout << ans << endl;    return 0;}
原创粉丝点击