gcd裸题,不过输入要注意gets会tle,要用快速读入
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<cassert> #include<iomanip> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-7; const int N=100000+10,maxn=500+100,inf=0x3f3f3f; ll a[N]; ll gcd(ll a,ll b) { if(a<b)swap(a,b); return b?gcd(b,a%b):a; } int main() { /* ios::sync_with_stdio(false); cin.tie(0);*/ ll n,ans=0; scanf("%d",&n); while (getchar() != '\n'); while (n --) { char buf; int cnt = 0; while ((buf = getchar()) != '\n') if (buf >= '0' && buf <= '9') { ungetc(buf,stdin); scanf("%d",&a[cnt++]); } ll ans=0; for(int i=0;i<cnt;i++) for(int j=i+1;j<cnt;j++) ans=max(ans,gcd(a[i],a[j])); printf("%lld\n",ans); } return 0; } /********************* 3 10 20 30 40 7 5 12 125 15 25 *********************/