QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#736854#9619. 乘积,欧拉函数,求和fsy_juruoWA 1ms3776kbC++171.3kb2024-11-12 13:41:402024-11-12 13:41:40

Judging History

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

  • [2024-11-12 13:41:40]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3776kb
  • [2024-11-12 13:41:40]
  • 提交

answer

#include <bits/stdc++.h>
using LL = long long;

const int MOD = 998244353;
const int maxN = 3e3 + 10;
int pi, primes[maxN], vis[maxN], phi[maxN];

int n, a[maxN], d[maxN][maxN], inv[maxN];
int pow_mod(int a, int b = MOD - 2) {
	int sum = 1;
	while(b) {
		if(b & 1) sum = 1ll * sum * a % MOD;
		a = 1ll * a * a % MOD;
		b >>= 1;
	}
	return sum;
}
void sieve(int LIM) {
	pi = 0;
	for(int i = 2; i <= LIM; i++) {
		if(!vis[i]) {
			primes[++pi] = i;
			phi[i] = i - 1;
		}
		for(int j = 1; j <= pi && primes[j] <= LIM / i; j++) {
			vis[i * primes[j]] = primes[j];
			if(i % primes[j] == 0) {
				phi[i * primes[j]] = phi[i] * primes[j];
			} else {
				phi[i * primes[j]] = phi[i] * (primes[j] - 1);
			}
		}
	}
}
int main() {
	std::ios::sync_with_stdio(false); std::cin.tie(nullptr);
	std::cin >> n;
	for(int i = 1; i <= n; i++) {
		std::cin >> a[i];
	}

	phi[1] = 1;
	sieve(3000);
	for(int i = 1; i <= 3000; i++) inv[i] = pow_mod(i);

	for(int i = 1; i <= n; i++) {
		for(int j = i + 1; j <= n; j++) {
			d[i][j] = std::__gcd(a[i], a[j]);
		}
	}

	int ans = 1;
	for(int i = 1; i <= n; i++) {
		int res = phi[a[i]];
		for(int j = i + 1; j <= n; j++) {
			res = 1ll * res * (1ll * phi[a[j]] * d[i][j] % MOD * inv[phi[d[i][j]]] % MOD + 1) % MOD; 
		}
		ans = (ans + res) % MOD;
	}

	std::cout << ans << "\n";
	return 0;
} 

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3776kb

input:

5
1 6 8 6 2

output:

536

result:

wrong answer 1st lines differ - expected: '892', found: '536'