QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#742667 | #9619. 乘积,欧拉函数,求和 | ATM12345# | TL | 65ms | 7268kb | C++17 | 2.2kb | 2024-11-13 17:03:05 | 2024-11-13 17:03:05 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define LL long long
#define ls p<<1
#define rs p<<1|1
#define Ma 30005
#define mod 998244353
#define PLL pair<ll,ll>
#define PDD pair<double,double>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define N 16
#define pb push_back
#define ld long double
#define all(x) x.begin(),x.end()
#define inf 1e18
using namespace std;
ll n,m,k;
ll a[Ma];
ll p[16]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};//16
//53*59
struct node{
vector <ll> v;
ll col,x;
bool operator <(const node &A)const{
return v.back()<A.v.back();
}
bool operator !=(const node &A)const{
return v.back()!=A.v.back();
}
}T[Ma];
ll po(ll p,ll x=mod-2)
{
ll sum=1;
while (x)
{
if (x&1) sum=(LL)sum*p%mod;
p=(LL)p*p%mod;
x>>=1;
}
return sum;
}
ll pw[Ma];
void go(ll x,ll id)
{
T[id].x=x;
vector <ll> v;
ll col=0;
if (x==1)
{
v.pb(1);
T[id].v=v,T[id].col=col;
return;
}
for (ll i=0;i<N;i++)
{
while (x%p[i]==0)
x/=p[i],v.pb(p[i]),col|=(1<<i);
}
if (x!=1)
v.pb(x);
T[id].v=v,T[id].col=col;
return;
}
ll dp[1<<N][2],ne[1<<N][2];
void add(ll &x,ll y)
{
x=(x+y)%mod;
}
void sol()
{
for (ll i=1;i<Ma;i++)
pw[i]=po(i);
cin>>n;
for (ll i=1;i<=n;i++)
{
ll x;
cin>>x;
go(x,i);
}
sort(T+1,T+n);
dp[0][0]=1;
for (ll i=1;i<=n;i++)
{
if (i>1&&T[i]!=T[i-1])
{
for (ll j=0;j<(1<<N);j++)
add(dp[j][0],dp[j][1]),dp[j][1]=0;
}
for (ll j=0;j<(1<<N);j++)
ne[j][0]=dp[j][0],ne[j][1]=dp[j][1];
for (ll j=0;j<(1<<N);j++)
{
ll res0=T[i].x;
ll np=(j|T[i].col);
ll res1=res0;
if (T[i].v.back()>p[N-1])
res1=(LL)res1*(T[i].v.back()-1)%mod*po(T[i].v.back())%mod;
add(ne[np][1],((LL)dp[j][0]*res1+(LL)dp[j][1]*res0)%mod);
}
swap(ne,dp);
}
ll res=0;
for (ll i=0;i<(1<<N);i++)
{
ll ad=(dp[i][0]+dp[i][1])%mod;
for (ll j=0;j<N;j++)
if (i>>j&1)
ad=ad*(p[j]-1)%mod*po(p[j])%mod;
add(res,ad);
}
printf("%lld\n",res);
return;
}
int main()
{
IOS
ll tt=1;
//cin>>tt;
while (tt--)
sol();
return 0;
}
/*
3
1 2 3
2
71 67
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 65ms
memory: 7268kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 65ms
memory: 7184kb
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...