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

51nod_1179_计算N个数之间两两之间GCD的最大值_第1张图片




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

你可能感兴趣的:(数论)