QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#876455 | #9619. 乘积,欧拉函数,求和 | pengpeng_fudan | TL | 17ms | 5760kb | C++23 | 2.1kb | 2025-01-30 21:28:41 | 2025-01-30 21:28:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
const int c=16;
int ct[]={2,3,5,7,11,13,17,19,23,29,31,37,41,47,53,59};
ll dp[1<<16][2][2];
const ll M=998244353;
void solve() {
int n;
cin>>n;
vector<pair<int,int>> a(n);
for(int i=0;i<n;i++){
ll x;
cin>>x;
a[i].second=x;
for(int j=0;j<c;j++){
while(x%ct[j]==0) x/=ct[j];
}
if(x!=1) a[i].first=x;
}
sort(a.begin(),a.end());
dp[0][0][0]=1;
for(int i=1;i<=n;i++){
auto [u,x]=a[i-1];
if(a[i-1].first==0||(i!=1&&a[i-1].first!=a[i-2].first)){
for(int j=0;j<(1<<c);j++){
dp[j][i&1][0]=dp[j][(i-1)&1][0]+dp[j][(i-1)&1][1];
dp[j][i&1][1]=0;
}
ll rq=0;
for(int j=0;j<(1<<c);j++){
ll gx=x,nxt=0;
for(int k=0;k<c;k++){
if(x%ct[k]==0){
nxt|=(1<<k);
if(!(j&(1<<k))) gx=gx/ct[k]*(ct[k]-1);
}
}
dp[j|nxt][i&1][1]=(dp[j|nxt][i&1][1]+(dp[j][(i-1)&1][0]+dp[j][(i-1)&1][1])%M*gx%M)%M;
}
}
else{
for(int j=0;j<(1<<c);j++){
dp[j][i&1][0]=dp[j][(i-1)&1][0];
dp[j][i&1][1]=dp[j][(i-1)&1][1];
}
for(int j=0;j<(1<<c);j++){
ll gx=x,nxt=0;
for(int k=0;k<c;k++){
if(x%ct[k]==0){
nxt|=(1<<k);
if(!(j&(1<<k))) gx=gx/ct[k]*(ct[k]-1);
}
}
dp[j|nxt][i&1][1]=(dp[j|nxt][i&1][1]+dp[j][(i-1)&1][0]*(gx/u*(u-1))%M+dp[j][(i-1)&1][1]*gx%M)%M;
}
}
}
ll ans=0;
for(int i=0;i<(1<<c);i++) ans=(ans+dp[i][n&1][0]+dp[i][n&1][1])%M;
cout<<(ans%M+M)%M;
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0);
int _ =1;
// cin>>_;
while(_--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 17ms
memory: 5632kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 16ms
memory: 5760kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: -100
Time Limit Exceeded
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...