QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#837641 | #9619. 乘积,欧拉函数,求和 | jiangzhihui | WA | 388ms | 4752kb | C++14 | 2.2kb | 2024-12-30 10:31:46 | 2024-12-30 10:31:47 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
const int N=3005;
int primes[16],cnt;
bool check(int x){
if(x<=1)return false;
for(int i=2;i*i<=x;i++){
if(x%i==0)return false;
}
return true;
}
void init(){
int idx=2;
while(cnt<16){
while(!check(idx))idx++;
primes[cnt++]=idx;
idx++;
}
}
struct node{
int v,s;
node(int v,int s):v(v),s(s){}
};
int n,a[N];
vector<node> g[N];
int val[1<<16];
int f[2][1<<16];
int pos[N],idx;
int ksm(int a,int b){
int res=1;
while(b){
if(b&1){
res=1ll*res*a%mod;
}
a=1ll*a*a%mod;
b>>=1;
}
return res;
}
int calc(int p){
if(p==1)return 1;
return (1-ksm(p,mod-2)+mod)%mod;
}
int tmp[1<<16];
int main(){
init();
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
int x=a[i];
int s=0;
for(int j=0;j<16;j++){
if(x%primes[j]==0){
s|=1<<j;
while(x%primes[j]==0)x/=primes[j];
}
}
g[x].push_back(node(a[i],s));
}
for(int i=1;i<=n;i++){
if(g[i].size()>0){
idx++;
pos[idx]=i;
}
}
for(int j=0;j<(1<<16);j++){
int res=1;
for(int i=0;i<16;i++){
if((j>>i)&1){
res=1ll*res*calc(primes[i])%mod;
}
}
val[j]=res;
}
f[0][0]=1;
for(int p=1,cur=1;p<=idx;p++,cur^=1){
for(int j=0;j<(1<<16);j++){
f[cur][j]=f[cur^1][j];
tmp[j]=f[cur^1][j];
}
int at=pos[p];
for(auto x:g[at]){
for(int j=(1<<16)-1;j>=0;j--){
tmp[j|x.s]=(tmp[j|x.s]+1ll*tmp[j]*x.v%mod)%mod;
}
}
int t=calc(at);
for(int j=0;j<(1<<16);j++){
tmp[j]-=f[cur^1][j];
tmp[j]=(tmp[j]+mod)%mod;
f[cur][j]=(f[cur][j]+1ll*tmp[j]*t%mod)%mod;
}
}
int ans=0;
for(int j=0;j<(1<<16);j++){
ans=(ans+1ll*f[idx&1][j]*val[j]%mod)%mod;
}
cout<<ans<<endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 66ms
memory: 4536kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 66ms
memory: 4452kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: -100
Wrong Answer
time: 388ms
memory: 4752kb
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:
282133628
result:
wrong answer 1st lines differ - expected: '50965652', found: '282133628'