QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#90365 | #5062. Square | ylf20010818# | RE | 0ms | 0kb | C++17 | 1.2kb | 2023-03-22 20:12:54 | 2023-03-22 20:12:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=1e6+10;
const ll mod=1e9+7;
const int M=1e3;
vector<ll> prims;
bool vis[M];
ll a[N];
void init(){
for(int i=2;i<=M;i++){
if(vis[i]) continue;
prims.push_back(i);
for(int j=i;j<=M/i;j++) vis[i*j]=1;
}
}
ll qpow(ll x,ll p){
ll res=1;
while(p){
if(p&1) res=res*x%mod;
x=x*x%mod;
p>>=1;
}
return res;
}
map<ll,ll> mp;
int main(){
init();
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
if(n==1){
cout<<1<<"\n";
return 0;
}
ll ans=1;
for(auto x:prims){
int cnt=0;
for(int i=1;i<=n;i++){
if(a[i]%(x*x)&&a[i]%x==0) {
cnt++;
}
while(a[i]%x==0) a[i]/=x;
}
ll mn=min(cnt,n-cnt);
// cout<<x<<" "<<mn<<"\n";
ans=ans*qpow(x,mn)%mod;
}
// cout<<ans<<"\n";
for(int i=1;i<=n;i++){
mp[a[i]]++;
}
for(auto x:mp){
ll t1=x.first,t2=x.second;
ll mn=min(n-t2,t2);
ans=ans*qpow(t1,mn)%mod;
}
cout<<ans<<"\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
3 2 3 6