QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#762631 | #9619. 乘积,欧拉函数,求和 | Terrible | WA | 0ms | 3652kb | C++14 | 1.4kb | 2024-11-19 15:55:18 | 2024-11-19 15:55:26 |
Judging History
answer
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll mod=998244353;
int main()
{
cin.tie(0)->sync_with_stdio(0);
vector<int> primes,notprime(3001);
for(int i=2;i<=3000;i++)
{
if(!notprime[i])primes.push_back(i);
for(int j=0,a;j<primes.size()&&((a=i*primes[j])<=3000);j++)
{
notprime[a]=1;
if(i%primes[j]==0)break;
}
}
// for(auto i:primes)cout<<i<<' ';cout<<endl;
int n;cin>>n;
vector<int> a(n);for(auto&i:a)cin>>i;
vector<vector<int>> pa(primes.size()),ap(n);
vector<int> ta=a;
vector<int> phia=a;
for(int i=0;i<n;i++)
{
for(int j=0;j<primes.size();j++)
{
int p=primes[j];
if(ta[i]%p==0)
{
phia[i]=(phia[i]/p)*(p-1);
pa[j].push_back(i);
ap[i].push_back(j);
while(ta[i]%p==0)ta[i]/=p;
}
}
}
// for(auto phi:phia)cout<<phi<<' ';cout<<endl;
// for(int i=0;i<n;i++){for(auto j:ap[i])cout<<j;cout<<endl;}cout<<endl;
// for(int j=0;j<primes.size();j++){for(auto i:pa[j])cout<<i;cout<<endl;}cout<<endl;
ll ans=1;
for(int b=0;b<n;b++)
{
vector<int> r=phia;
for(auto j:ap[b])
{
int p=primes[j];
for(auto i:pa[j])r[i]=r[i]/(p-1)*p;
}
ll prod=1;
for(int i=b+1;i<n;i++)
prod=prod*(1ll+r[i])%mod;
ans=(ans+phia[b]*prod)%mod;
}
cout<<ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3652kb
input:
5 1 6 8 6 2
output:
536
result:
wrong answer 1st lines differ - expected: '892', found: '536'