Untitled

mail@pastecode.io avatar
unknown
c_cpp
3 years ago
1.3 kB
10
Indexable
Never
#include <iostream>
#include  <bits/stdc++.h>

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 t;
    cin >> t;

     string temp;
    getline(cin, temp);

    while(t--)
    {

        string s;
        getline(cin, s);

        int len = s.length();

        int arr[len] = {0};

        int j = 0, i;


        for (i = 0; s[i] != '\0'; i++)
        {

            if (s[i] == ' ')
            {

                j++;
            }
            else
            {

                arr[j] = arr[j] * 10 + (s[i] - 48);


            }


        }


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


    }


}