QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#776866#9619. 乘积,欧拉函数,求和ucup-team3548#WA 510ms5948kbC++202.0kb2024-11-23 21:22:052024-11-23 21:22:05

Judging History

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

  • [2024-11-23 21:22:05]
  • 评测
  • 测评结果:WA
  • 用时:510ms
  • 内存:5948kb
  • [2024-11-23 21:22:05]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define MOD(X) ((X)>=Mod?(X)-Mod:(X))
using namespace std;
const ll Mod=998244353;
const int Maxstate=(1<<16);
ll Pow(ll X,ll K)
{
    ll Res=1;
    ll Times=X;
    while(K)
    {
        if(K&1)Res=Res*Times%Mod;
        Times=Times*Times%Mod;
        K>>=1;
    }
    return Res;
}
int N;
int Prime[17]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
struct num
{
    ll Num;
    ll Maxf;
    int State;
}A[2001];
ll DP[2][(1<<16)+10][2];
ll Invv[17];
bool Cmp(num &B,num &C)
{
    return B.Maxf<C.Maxf;
}
int main()
{
    for(int i=0;i<16;++i)
    Invv[i]=Pow(Prime[i],Mod-2)*(Prime[i]-1)%Mod;
    scanf("%d",&N);
    for(int i=1;i<=N;++i)
    {
        scanf("%d",&A[i].Num);
        ll Copy=A[i].Num;
        for(int j=0;j<16;++j)
        {
            if(Copy%Prime[j]==0)
            A[i].State|=(1<<j);
            while(Copy%Prime[j]==0)
            Copy/=Prime[j];
        }
        A[i].Maxf=Copy;
    }
    sort(A+1,A+N+1,Cmp);
    DP[0][0][0]=1;
    for(int i=1;i<=N;++i)
    {
        memset(DP[i&1],0,sizeof(DP[i&1]));
        if(i>1&&A[i-1].Maxf>1&&A[i].Maxf!=A[i-1].Maxf)
        {
            ll Inv=Pow(A[i-1].Maxf,Mod-2);
            for(int j=0;j<Maxstate;++j)
            {
                DP[!(i&1)][j][0]=MOD(DP[!(i&1)][j][0]+DP[!(i&1)][j][1]*(A[i-1].Maxf-1)%Mod*Inv%Mod);
                DP[!(i&1)][j][1]=0;
            }
        }
        for(int j=0;j<Maxstate;++j)
        {
            DP[i&1][j][0]=DP[!(i&1)][j][0];
            DP[i&1][j][1]=MOD(DP[i&1][j][1]+DP[!(i&1)][j][1]);
            DP[i&1][j|A[i].State][1]=(DP[i&1][j|A[i].State][1]+(DP[!(i&1)][j][0]+DP[!(i&1)][j][1])*A[i].Num%Mod)%Mod;
        }
    }
    ll Ans=0;
    ll Inv=(A[N].Maxf>1?(Pow(A[N].Maxf,Mod-2)*(A[N].Maxf-1)%Mod):1);
    for(int i=0;i<Maxstate;++i)
    {
        ll Now=(DP[N&1][i][0]+DP[N&1][i][1]*Inv%Mod)%Mod;
        for(int j=0;j<16;++j)
        if(i&(1<<j))
        Now=Now*Invv[j]%Mod;
        Ans+=Now;
    }
    printf("%lld\n",Ans%Mod);
}

详细

Test #1:

score: 100
Accepted
time: 6ms
memory: 5948kb

input:

5
1 6 8 6 2

output:

892

result:

ok single line: '892'

Test #2:

score: 0
Accepted
time: 6ms
memory: 5940kb

input:

5
3 8 3 7 8

output:

3157

result:

ok single line: '3157'

Test #3:

score: -100
Wrong Answer
time: 510ms
memory: 5828kb

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:

846559347

result:

wrong answer 1st lines differ - expected: '50965652', found: '846559347'