QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#746926 | #9619. 乘积,欧拉函数,求和 | Tggdb | WA | 402ms | 4896kb | C++20 | 1.9kb | 2024-11-14 15:52:59 | 2024-11-14 15:52:59 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
constexpr int mod=998244353;
int isprime[3005],prime[3000],cnt;
vector<int> use[3005];
int inv[3005];
void paralysis(){
for (int i=2;i<=3000;i++){
if (!isprime[i]) prime[++cnt]=i;
for(int j=1;j<=cnt&&i*prime[j]<=3000;j++){
isprime[i*prime[j]]=1;
if (i%prime[j]==0){
break;
}
}
}
vector<int> p;
for (int i=2;i<=53;i++){
if (!isprime[i]){
p.push_back(i);
}
}
int n;
cin>>n;
vector<int> a(n+1);
for (int i=1;i<=n;i++){
cin>>a[i];
}
for (int i=1;i<=n;i++){
int now=a[i];
for (auto x:p){
while (now%x==0){
now/=x;
}
}
use[now].push_back(a[i]);
}
vector<int> f(1<<16);
f[0]=1;
for (auto x:use[1]){
int mask=0;
for (int i=0;i<p.size();i++){
if (x%p[i]==0){
mask|=(1<<i);
}
}
auto res=f;
for (int i=0;i<(1<<16);i++){
f[i|mask]=(f[i|mask]+1LL*res[i]*x%mod)%mod;
}
}
for (int i=54;i<=3000;i++){
if (use[i].size()==0) continue;
vector<vector<int>> dp(2,vector<int>(1<<16));
dp[0]=f;
for (auto x:use[i]){
auto res=dp;
int mask=0;
for (int j=0;j<p.size();j++){
if (x%p[j]==0){
mask|=(1<<j);
}
}
for (int j=0;j<(1<<16);j++){
dp[1][j|mask]=(dp[1][j|mask]+1LL*res[0][j]*x%mod)%mod;
}
}
for (int j=0;j<(1<<16);j++){
f[j]=(dp[0][j]+1LL*dp[1][j]*(i-1)%mod*inv[i-1]%mod)%mod;
}
}
int ans=0;
for (int i=0;i<(1<<16);i++){
int s=1;
for (int j=0;j<16;j++){
if (i>>j&1){
s=1LL*s*(p[j]-1)%mod*inv[p[j]]%mod;
}
}
ans=(ans+1LL*f[i]*s%mod)%mod;
}
cout<<ans<<"\n";
}
/*
3
1 2 3
*/
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
for (int i=1;i<=3000;i++){
inv[i]=(i==1?1:1LL*(mod-mod/i)*inv[mod%i]%mod);
}
int t=1;
// cin>>t;
while (t--){
paralysis();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 6ms
memory: 3992kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 6ms
memory: 3904kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: -100
Wrong Answer
time: 402ms
memory: 4896kb
input:
2000 79 1 1 1 1 1 1 2803 1 1 1 1 1 1 1609 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2137 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 613 1 499 1 211 1 2927 1 1 1327 1 1 1123 1 907 1 2543 1 1 1 311 2683 1 1 1 1 2963 1 1 1 641 761 1 1 1 1 1 1 1 1 1 1 1 1489 2857 1 1 1 1 1 1 1 1 1 1 1 1 1 967 1 821 1 1 1 1 2143 1861...
output:
138739741
result:
wrong answer 1st lines differ - expected: '50965652', found: '138739741'