QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#739705 | #9619. 乘积,欧拉函数,求和 | Wolam | WA | 815ms | 5848kb | C++20 | 3.2kb | 2024-11-12 22:44:47 | 2024-11-12 22:44:47 |
Judging History
answer
#include<bits/stdc++.h>
#define endl "\n"
#define int long long
using namespace std;
using ll = long long;
const int mod = 998244353;
const int unit = 47;
const int maxn = (1<<15) + 10;
const int all = (1<<15) - 1;
const int N = 15;
vector<pair<ll,int>> vec[3010];
ll dp1[(1<<16)+10],dp2[(1<<16)+10],g[2][(1<<16)+10];
int bit[60],p[20],a[2010];
ll inv[3005];
ll qpow(ll n,ll m)
{
if(m<0)
{
return qpow(qpow(n,mod-2),-m);
}
n%=mod;
ll res=1;
while(m)
{
if(m&1)
{
res=res*n%mod;
}
n=n*n%mod;
m>>=1;
}
return res;
}
void calc(int i)//calc dp2
{
for(int s=0;s<=all;s++)
{
g[0][s]=g[1][s]=0;
}
int pos=0;
for(auto [v,s1] : vec[i])
{
for(int s=0;s<=all;s++)
{
g[pos][s]=g[pos^1][s];
}
(g[pos][s1]+=v)%=mod;
for(int s=0;s<=all;s++)
{
if((s&s1)==s1)
{
for(int s2=s1;s2;s2=s1&(s2-1))
{
(g[pos][s]+=v*g[pos^1][s2|(s1^s)]%mod)%=mod;
}
(g[pos][s]+=v*g[pos^1][s1^s]%mod)%=mod;
}
}
pos^=1;
}
for(int s=0;s<=all;s++)
{
if(i!=1)
{
dp2[s]=g[pos^1][s]*(i-1)%mod*inv[i]%mod;
}
else
{
dp2[s]=g[pos^1][s];
}
}
dp2[0]++;
}
void OR(ll *f,int x=1)
{
for(int d=2,k=1;d<=(1<<N);d<<=1,k<<=1)
{
for(int i=0;i<(1<<N);i+=d)
for(int j=0;j<k;j++)
{
(f[i+j+k]+=f[i+j]*(x+mod)%mod)%=mod;
}
}
}
void merge(void)//merge dp1 and dp2 to dp1
{
OR(dp1,1);
OR(dp2,1);
for(int i=0;i<=(1<<N);i++)
dp1[i]=dp1[i]*dp2[i]%mod;
OR(dp1,-1);
}
void solve(void)
{
int now=0;
for(int i=2;i<=unit;i++)
{
bool valid=true;
for(int j=2;j<i;j++)
{
if(i%j==0)
{
valid=false;
break;
}
}
if(valid)
{
bit[i]=now++;
p[now-1]=i;
}
}
int n;
//n=2000;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
//a[i]=i;
now=a[i];
int s=0;
for(int j=2;j<=unit;j++)
{
while(now%j==0)
{
s|=(1<<bit[j]);
now/=j;
}
}
vec[now].emplace_back(a[i],s);
}
dp1[0]=1;
for(int i=1;i<=3000;i++)
{
if(vec[i].empty())
{
continue;
}
calc(i);
merge();
}
ll ans=0;
for(int s=0;s<=all;s++)
{
for(int i=0;i<N;i++)
{
if(s>>i&1)
{
(dp1[s]*=(p[i]-1)*inv[p[i]]%mod)%=mod;
}
}
(ans+=dp1[s])%=mod;
}
cout<<ans<<endl;
}
signed main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
for(int i=1;i<=3000;i++)
inv[i]=qpow(i,-1);
int t=1;
while(t--)
{
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 4724kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 5ms
memory: 4656kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: 0
Accepted
time: 815ms
memory: 4928kb
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:
50965652
result:
ok single line: '50965652'
Test #4:
score: -100
Wrong Answer
time: 808ms
memory: 5848kb
input:
2000 1 1 1 1 1 1 1 1 353 1 1 1 557 1 1 1 1 1 1 1 1 1 1 1 1423 1 1 1327 1 1 1 907 1 1 1 1 1 2971 1 1 1 2531 1 1 1 1 1 1 1 1 1 2099 1 1 1 1 1 1 1 1 1 1 1 1 1 1 199 2999 1 727 1 1 1 1 1 1 1 71 1 1 1 1 1 1 2503 1 176 1 1 1 1 1 1 1361 1013 1 1 1 1 1 1 1 2699 1 1 1 1 1 1 1 1 1 2897 1 1 1 1 1637 1 1 1367 1...
output:
637200514
result:
wrong answer 1st lines differ - expected: '420709530', found: '637200514'