QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#762631#9619. 乘积,欧拉函数,求和TerribleWA 0ms3652kbC++141.4kb2024-11-19 15:55:182024-11-19 15:55:26

Judging History

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

  • [2024-11-19 15:55:26]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3652kb
  • [2024-11-19 15:55:18]
  • 提交

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;
}

详细

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'