标签:namespace can out problems viso 代码 style signed its
题目链接:https://codeforces.com/problemset/problem/1165/D
AC代码:
1 #include<bits/stdc++.h> 2 using namespace std; 3 # define ll unsigned long long 4 # define inf 0x3f3f3f3f 5 const int maxn = 2e5+100; 6 const ll mod = 998244353 ; 7 ll a[maxn]; 8 int main() 9 { 10 int T; 11 scanf("%d",&T); 12 while(T--) 13 { 14 int n; 15 scanf("%d",&n); 16 for(int i=1; i<=n; i++) 17 { 18 scanf("%lld",&a[i]); 19 } 20 sort(a+1,a+n+1); 21 ll ans=a[1]*a[n]; 22 int flag=1; 23 for(int i=1; i<=n; i++) 24 { 25 if(ans%a[i]!=0) 26 flag=0; 27 } 28 if(!flag) 29 { 30 printf("-1\n"); 31 } 32 else 33 { 34 ll tmp=(int)sqrt(ans); 35 int cnt=0; 36 for(ll i=2; i<=tmp; i++) 37 { 38 if(ans%i==0) 39 { 40 cnt++; 41 if(ans/i!=i)cnt++;// 如果是9=3*3这类的,应该算一个 42 } 43 } 44 // cout<<cnt<<endl; 45 if(cnt==n) 46 printf("%lld\n",ans); 47 else printf("-1\n"); 48 } 49 } 50 return 0; 51 }
标签:namespace can out problems viso 代码 style signed its
原文地址:https://www.cnblogs.com/letlifestop/p/10908828.html