-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path11287.cpp
76 lines (66 loc) · 1.37 KB
/
11287.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include<bits/stdc++.h>
using namespace std;
vector<int>getVector(string str)
{
vector<int>num;
int t=0;
int sz=str.size();
for(int i=0;i<sz;i++)
{
if(str[i]!=' ')
{
t=t*10+(str[i]-'0');
}
if(str[i]==' ' || i==sz-1)
{
if(t!=0)
{
//printf("Calculated");
num.push_back(t);
t=0;
}
}
}
return num;
}
int gcd(int a,int b)
{
if(b==0) return a;
else return gcd(b,a%b);
}
int main()
{
//freopen("input.txt","r",stdin);
vector<int>numList;
string str;
int T;
scanf("%d",&T);
getchar();
for(int i=1;i<=T;i++)
{
getline(cin,str);
int res=0;
numList=getVector(str);
int sz=numList.size();
for(int i=0;i<sz;i++)
{
for(int j=i+1;j<sz;j++)
{
int x=numList[i];
int y=numList[j];
if(numList[i]<numList[j])
{
x=numList[j];
y=numList[i];
}
int g=gcd(x,y);
if(g>res)
{
res=g;
}
}
}
printf("%d\n",res);
}
return 0;
}