-
Notifications
You must be signed in to change notification settings - Fork 0
/
11827_maxGCD.cpp
60 lines (48 loc) · 938 Bytes
/
11827_maxGCD.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
using namespace std;
#include<iostream>
#include<cstring>
#include<stdio.h>
#define max(a,b) (a>b)?a:b
int FindGcd(int a , int b)
{
if(b==0)
return a;
else
return FindGcd (b , a%b);
}
int main()
{
string str;
int T,arr[110],i,m,k,temp,ans;
char c;
cin>>T;
getchar();
while(T--)
{
memset(arr , 0 ,sizeof arr);
getline(cin,str);
m=i=k=0;
while(i<str.length())
{
temp=0;
while(i<str.length()&&str[i]!=' ')
{
i++;
}
while(k<i)
{
temp=(str[k]-48)+(temp*10);
k++;
}
arr[m++]=temp;
i++;
k++;
}
ans=1;
for(i=0;i<m;i++)
for(k=i+1;k<m;k++)
ans=max(ans,FindGcd(arr[i],arr[k]));
cout<<ans<<endl;
}
return 0;
}