QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#737007#9619. 乘积,欧拉函数,求和hezlik#WA 420ms6088kbC++201.5kb2024-11-12 14:14:382024-11-12 14:14:40

Judging History

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

  • [2024-11-12 14:14:40]
  • 评测
  • 测评结果:WA
  • 用时:420ms
  • 内存:6088kb
  • [2024-11-12 14:14:38]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N=(1<<16)+7,p=998244353;
int n,k,f[N],w[N],dp[3][N]; int g[N]; vector<int>vt[N];
long long pows(long long u,int v){
  long long ans=1;
  while(v>0){
    if(v&1) ans=ans*u%p; u=u*u%p,v=v>>1;
  }
  return ans;
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  for(int i=2;i<=54;i++){
    g[i]=++k; w[k]=i;
    for(int j=2;j*j<=i;j++){
      if(i%j==0){
        k--,g[i]=0; break;
      }
    }
  }
  cin>>n;
  while(n--){
    int x; cin>>x; int num=x;
    for(int i=2;i<=54;i++) while(x%i==0) x/=i;
    vt[x].push_back(num);
  }
  dp[0][0]=1;
  for(int i=1;i<=2000;i++){
    if(vt[i].size()){
      for(int x:vt[i]){
        int D=0;
        for(int c=2;c<=54;c++){
          if(!g[c]) continue;
          if(x%c==0) D|=(1<<(g[c]-1));
        }
        for(int z=0;z<(1<<16);z++){
          dp[2][z|D]=(dp[2][z|D]+1ll*(dp[1][z]+dp[0][z])*x)%p;
        }
        for(int z=0;z<(1<<16);z++)
          dp[1][z]=(dp[1][z]+dp[2][z])%p,dp[2][z]=0;
      }
      long long inv=pows(i,p-2);
      for(int z=0;z<(1<<16);z++){
        if(i>1) dp[0][z]=(dp[0][z]+dp[1][z]*inv%p*(i-1))%p;
        else dp[0][z]=(dp[0][z]+dp[1][z])%p;
        dp[1][z]=0;
      }
    }
  }
  int ans=0;
  for(int z=0;z<(1<<16);z++){
    for(int x=1;x<=k;x++)
      if((z>>(x-1))&1)
        dp[0][z]=dp[0][z]*pows(w[x],p-2)%p*(w[x]-1)%p;
    ans=(ans+dp[0][z])%p;
  }
  cout<<ans;

}
/*
3
1 2 3
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 59ms
memory: 4428kb

input:

5
1 6 8 6 2

output:

892

result:

ok single line: '892'

Test #2:

score: 0
Accepted
time: 63ms
memory: 6088kb

input:

5
3 8 3 7 8

output:

3157

result:

ok single line: '3157'

Test #3:

score: -100
Wrong Answer
time: 420ms
memory: 4464kb

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:

282133628

result:

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