#include<bits/stdc++.h>
using namespace std;
vector<int>v;
void anik(string s)
{
string p = "";
int l = s.size(), i;
for(i=0; i<l; i++)
{
if(s[i] == ' ' && p == "")
continue;
if(s[i] == ' ')
{
int t = stoi(p);
v.push_back(t);
p = "";
}
else
p.push_back(s[i]);
}
if(p != "")
{
int t = stoi(p);
v.push_back(t);
}
}
int gcd(int a, int b)
{
if(b == 0)
return a;
return gcd(b, a%b);
}
int main()
{
string s;
int n, i, j, k, mx;
while(cin >> n)
{
getchar();
for(k=1; k<=n; k++)
{
getline(cin, s);
anik(s);
int l = v.size(), mx = 0;
for(i=0; i<l-1; i++)
{
for(j=i+1; j<l; j++)
{
int t = gcd(v[i], v[j]);
if(mx < t)
mx = t;
}
}
cout << mx << endl;
v.clear();
}
}
return 0;
}
using namespace std;
vector<int>v;
void anik(string s)
{
string p = "";
int l = s.size(), i;
for(i=0; i<l; i++)
{
if(s[i] == ' ' && p == "")
continue;
if(s[i] == ' ')
{
int t = stoi(p);
v.push_back(t);
p = "";
}
else
p.push_back(s[i]);
}
if(p != "")
{
int t = stoi(p);
v.push_back(t);
}
}
int gcd(int a, int b)
{
if(b == 0)
return a;
return gcd(b, a%b);
}
int main()
{
string s;
int n, i, j, k, mx;
while(cin >> n)
{
getchar();
for(k=1; k<=n; k++)
{
getline(cin, s);
anik(s);
int l = v.size(), mx = 0;
for(i=0; i<l-1; i++)
{
for(j=i+1; j<l; j++)
{
int t = gcd(v[i], v[j]);
if(mx < t)
mx = t;
}
}
cout << mx << endl;
v.clear();
}
}
return 0;
}
Comments
Post a Comment