QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#745877#9619. 乘积,欧拉函数,求和lrher#RE 52ms61888kbC++143.3kb2024-11-14 12:08:152024-11-14 12:08:16

Judging History

你现在查看的是最新测评结果

  • [2024-11-14 12:08:16]
  • 评测
  • 测评结果:RE
  • 用时:52ms
  • 内存:61888kb
  • [2024-11-14 12:08:15]
  • 提交

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[1000010];
int tot,pri[1000010];
int vis[1000010],rk[1000010];
vector<int> g[1000010],fac[1000010];
long long dp[1000010],inv[1000010],lst[1000010];
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;
}
/*
36
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
*/

详细

Test #1:

score: 100
Accepted
time: 52ms
memory: 61732kb

input:

5
1 6 8 6 2

output:

892

result:

ok single line: '892'

Test #2:

score: 0
Accepted
time: 48ms
memory: 61888kb

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...

output:


result: