QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#745861 | #9619. 乘积,欧拉函数,求和 | lrher# | RE | 48ms | 5088kb | C++14 | 3.2kb | 2024-11-14 12:04:01 | 2024-11-14 12:04:10 |
Judging History
answer
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<deque>
#include<string>
#include<bitset>
#include<vector>
#include<cstdio>
#include<random>
#include<complex>
#include<cstdlib>
#include<climits>
#include<iomanip>
#include<cstring>
#include<cassert>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
// #define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
// char buf[1<<21],*p1=buf,*p2=buf;
const long long _base=107374183;
int writetemp[30];
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;
return x;
}
inline void write(unsigned long long x)
{
int tot=(x==0);
writetemp[1]=0;
while(x) writetemp[++tot]=x%10,x/=10;
while(tot) putchar(writetemp[tot--]+'0');
putchar('\n');
return ;
}
const int mod=998244353;
int n,a[3010];
int tot,pri[3010];
int vis[3010],rk[3010];
vector<int> g[3010],fac[3010];
long long dp[65536],inv[3010],lst[65536];
long long binpow(long long a,long long b)
{
long long res=1;
while(b)
{
if(b&1) res=(res*a)%mod;
a=a*a%mod,b>>=1;
}
return res;
}
void pd(long long &x)
{
if(x<0) x+=mod;
return ;
}
long long ans;
int main()
{
// freopen("s.out","r",stdin);
// freopen("a.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=3000;i++) inv[i]=(i-1)*binpow(i,mod-2)%mod;
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=2;i<=3000;i++)
{
if(!vis[i]) pri[++tot]=i,rk[i]=tot;
for(int j=i+i;j<=3000;j+=i) vis[j]=1;
}
// printf("pre\n");
for(int i=1;i<=n;i++)
{
int temp=a[i];
for(int j=1;j<=tot&&pri[j]<=a[i];j++) if(a[i]%pri[j]==0)
{
// printf("%d\n",pri[j]);
fac[i].push_back(pri[j]);
while(a[i]%pri[j]==0) a[i]/=pri[j];
}
a[i]=temp;
// printf("%d\n",a[i]);
}
dp[0]=1;
for(int i=1;i<=n;i++)
{
if(!fac[i].empty()&&fac[i].back()>53) g[rk[fac[i].back()]].push_back(i);
else
{
int now=0;
for(int j=0;j<fac[i].size();j++) now|=1<<(rk[fac[i][j]]-1);
for(int s=(1<<16)-1;s>=0;s--) (dp[s|now]+=dp[s]*a[i])%=mod;
}
}
// printf("finish dp1\n");
for(int now=17;now<=tot;now++)
{
for(int s=0;s<(1<<16);s++) lst[s]=dp[s];
for(int i=0;i<g[now].size();i++)
{
int pos=g[now][i],now=0;
for(int j=0;j<fac[pos].size()-1;j++) now|=1<<(rk[fac[i][j]]-1);
for(int s=(1<<16)-1;s>=0;s--) (dp[s|now]+=dp[s]*a[pos])%=mod;
}
for(int s=0;s<(1<<16);s++) dp[s]-=lst[s],pd(dp[s]),dp[s]=(dp[s]*inv[pri[now]]+lst[s])%mod;
}
for(int s=0;s<(1<<16);s++)
{
long long mul=1;
for(int i=1;i<=16;i++) if(s>>(i-1)&1) (mul*=inv[pri[i]])%=mod;
// if(dp[s]) printf("%d %lld\n",s,dp[s]);
(ans+=mul*dp[s])%=mod;
}
printf("%lld\n",ans);
return 0;
}
/*
*/
详细
Test #1:
score: 100
Accepted
time: 45ms
memory: 5088kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 48ms
memory: 4992kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: -100
Runtime Error
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...