QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#567790 | #5062. Square | H_ZzZ# | TL | 11ms | 16980kb | C++20 | 1.5kb | 2024-09-16 13:55:57 | 2024-09-16 13:56:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N=1e6+50,mod=1e9+7;
int a[N],t[N];
int primes[N],dv[N],cnt;
bool st[N];
void init()
{
int n=1e6+5;
for(int i=2;i<=n;i++)
{
if(!st[i])primes[++cnt]=i,dv[i]=1;
for(int j=1;primes[j]*i<=n;j++)
{
st[primes[j]*i]=true;
dv[primes[j]*i]=i;
if(i%primes[j]==0)break;
}
}
}
int qmi(int a,int b)
{
int res=1;
while(b)
{
if(b&1)res=res*a%mod;
a=a*a%mod;
b>>=1;
}
return res;
}
void solve()
{
init();
int n;
cin>>n;
map<int,int> mp;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)
{
if(mp[a[i]]!=0)a[i]=mp[a[i]];
int tmp=a[i];
for(int j=2;j*j<=tmp;j++)
{
if(tmp%(j*j)==0)tmp/=(j*j);
}
mp[a[i]]=tmp;
a[i]=tmp;
}
map<int,int> t;
for(int i=1;i<=n;i++)
{
while(a[i]!=1)
{
int x=a[i]/dv[a[i]];
a[i]=dv[a[i]];
t[x]++;
}
}
int ans=1;
for(auto [x,y]:t)
{
y = min(y,n-y);
ans=ans*qmi(x,y)%mod;
}
cout<<ans;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int T=1;
//cin >> T;
while(T--)
{
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 15952kb
input:
3 2 3 6
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 7ms
memory: 16572kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 11ms
memory: 16980kb
input:
100000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 8ms
memory: 16444kb
input:
1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Time Limit Exceeded
input:
1 130321