Untitled

mail@pastecode.io avatar
unknown
c_cpp
3 years ago
841 B
2
Indexable
Never
#include <iostream>

using namespace std;

int findMaxGCD(int arr[], int n)
{

    int h = 0;
    for (int i = 0; i < n; i++)
       {
           h = max(h, arr[i]);
       }

    int d[h + 1] = { 0 };

    for (int i = 0; i < n; i++)
    {

        for (int j = 1; j * j <= arr[i]; j++)
        {

            if (arr[i] % j == 0)
            {

                d[j]++;

                if (j != arr[i] / j)
                    d[arr[i] / j]++;
            }
        }
    }


    for (int i = h; i >= 1; i--)

      {
          if (d[i] > 1)
            {
                return i;
            }

      }
}




int main()
{
    int n;
    cin >> n;

    int arr[n];

    for(int i=0; i<n; i++)
    {
        cin >> arr[i];
    }

    cout << findMaxGCD(arr, n+1) << "\n";



}