QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#800247#9619. 乘积,欧拉函数,求和DarwinA66WA 606ms6476kbC++203.5kb2024-12-06 03:23:282024-12-06 03:23:29

Judging History

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

  • [2024-12-06 03:23:29]
  • 评测
  • 测评结果:WA
  • 用时:606ms
  • 内存:6476kb
  • [2024-12-06 03:23:28]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=3010;
ll mod=998244353;
ll n;
ll pri[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
ll a[N],s[N],v[N];
ll id[N];
ll st[1<<16];
ll dp[1<<16];
ll add_dp[1<<16];
ll tp[1<<16];
ll add_tp[1<<16];
bool cmp(ll x,ll y)
{
    return v[x]<v[y];
}
ll fastpow(ll x,ll p)
{
    ll base=x;
    ll res=1ll;
    while(p)
    {
        if(p&1ll)res=(res*base)%mod;
        base=(base*base)%mod;
        p>>=1ll;
    }
    return res;
}
ll mod_inverse(ll x)
{
    ll res=fastpow(x,mod-2);
    return res;
}
int main()
{
    scanf("%lld",&n);
    ll one_cnt=0ll;
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        if(a[i]==1ll)one_cnt++;
        id[i]=i*1ll;
        ll temp=a[i];
        ll max_p=1ll;
        for(int j=0;j<16;j++)
        {
            while(temp%pri[j]==0)
            {
                temp/=pri[j];
                s[i]|=1ll<<j;
                max_p=pri[j]*1ll;
            }
        }
        if(temp>1)v[i]=temp;
        else v[i]=max_p;
    }
    sort(id+1,id+1+n);
    for(ll mask=0;mask<1ll<<16;mask++)
    {
        ll temp=1ll;
        for(int j=0;j<16;j++)
        {
            if(mask&(1ll<<j))
            {
                temp=(temp*(pri[j]-1ll))%mod;
                temp=(temp*mod_inverse(pri[j]))%mod;
            }
        }
        st[mask]=temp;
    }
    dp[0]=1ll;
    ll pre_prime=1ll;
    for(int i=1;i<=n;i++)
    {
        if(a[id[i]]==1ll)continue;
        for(ll mask=0;mask<(1ll<<16);mask++)
        {
            add_dp[mask]=0ll;
            add_tp[mask]=0ll;
        }
        if(v[id[i]]<=53)
        {
            for(ll mask=0;mask<(1<<16);mask++)
            {
                if(dp[mask]>=1ll)
                {
                    add_dp[mask|s[id[i]]]=(add_dp[mask|s[id[i]]]+(((dp[mask]*a[id[i]]*1ll)%mod))%mod)%mod;
                }
            }
            for(ll mask=0;mask<(1<<16);mask++)
            {
                dp[mask]=(dp[mask]+add_dp[mask])%mod;
            }
        }
        else
        {
            if(v[id[i]]!=pre_prime)
            {
                for(ll mask=0;mask<(1ll<<16);mask++)
                {
                    dp[mask]=(dp[mask]+tp[mask])%mod;
                    tp[mask]=0ll;
                }
            }
            for(ll mask=0;mask<(1ll<<16);mask++)
            {
                if(dp[mask]>=1ll)
                {
                    ll num=(((dp[mask]*a[id[i]]*1ll)%mod))%mod;
                    num=(((num*(v[id[i]]-1ll))%mod)*mod_inverse(v[id[i]]))%mod;
                    add_dp[mask|s[id[i]]]=(add_dp[mask|s[id[i]]]+num*1ll)%mod;
                }
                if(tp[mask]>=1ll)
                {
                    add_tp[mask|s[id[i]]]=(add_tp[mask|s[id[i]]]+(((tp[mask]*a[id[i]]*1ll)%mod))%mod)%mod;
                }
            }
            for(ll mask=0;mask<(1ll<<16);mask++)
            {
                tp[mask]=(((tp[mask]+add_dp[mask])%mod)+add_tp[mask])%mod;
                if(i==n)dp[mask]=(dp[mask]+tp[mask])%mod;
            }
            pre_prime=v[id[i]];
        }
    }
    ll ans=0ll;
    for(ll mask=0;mask<(1<<16);mask++)
    {
        ans=(((ans+(dp[mask]*st[mask])%mod)%mod)+(tp[mask]*0ll)%mod)%mod;
    }
    ans=(ans*1ll*fastpow(2ll,one_cnt))%mod;
    printf("%lld\n",ans);
    return 0;
}
/*
20
1 1 11 121 255 289 1888 885 788 1145 2242 2714 2211 2948 2803 2927 764 661 1858 1949
372472595
*/

詳細信息

Test #1:

score: 100
Accepted
time: 131ms
memory: 6036kb

input:

5
1 6 8 6 2

output:

892

result:

ok single line: '892'

Test #2:

score: 0
Accepted
time: 128ms
memory: 5996kb

input:

5
3 8 3 7 8

output:

3157

result:

ok single line: '3157'

Test #3:

score: -100
Wrong Answer
time: 606ms
memory: 6476kb

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:

683292323

result:

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