这段代码时答案给的参考代码:
#include<bits/stdc++.h>
using namespace std;
const int mod=1000000007;
int f[10005];
vector<int> p;
int a[10005];
priority_queue<int> que;
int read() {
char c=getchar(); int x=0;
while (c<'0' || c>'9') c=getchar();
while (c>='0' && c<='9') {
x=x*10+c-'0';
c=getchar();
}
return x;
}
int main() {
memset(f,0,sizeof(f));
for (int i=2; i<=10000; i++) {
if (f[i]==0) {
p.push_back(i);
for (int j=i*2; j<=10000; j+=i) f[j]=1;
}
}
int T=read();
while (T--) {
int n=read();
for (int i=1; i<=n; i++) a[i]=read();
long long ans=1;
for (int i=0; i<p.size(); i++) {
for (int j=1; j<=n; j++) {
int t=0;
while (a[j]%p[i]==0) a[j]/=p[i],++t;
if (t>0) que.push(t);
}
while (que.size()>1) {
int a=que.top(); que.pop();
int b=que.top(); que.pop();
--a; --b;
if (a>0) que.push(a);
if (b>0) que.push(b);
}
if (que.empty()) que.push(0);
int cnt=que.top(); que.pop();
while (cnt--) ans=(ans*p[i])%mod;
}
sort(a+1,a+n+1);
for (int i=1; i<=n-1; i++) {
if (a[i]==a[i+1]) {
a[i]=a[i+1]=1;
}
}
for (int i=1; i<=n; i++) ans=(ans*a[i])%mod;
printf("%lld\n", ans);
}
return 0;
}