QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#737093#9619. 乘积,欧拉函数,求和fsy_juruoWA 1ms3776kbC++171.9kb2024-11-12 14:36:442024-11-12 14:36:54

Judging History

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

  • [2024-11-12 14:36:54]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3776kb
  • [2024-11-12 14:36:44]
  • 提交

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], f[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 <= 100; i++) {
	// 	std::cout << inv[i] << " \n"[i % 10 == 0];
	// }
	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 = n; i >= 1; i--) {
		// f[i] = phi[a[i]];
		f[i] = phi[a[i]];
		for(int j = i + 1; j <= n; j++) {
			f[i] = (f[i] + 1ll * f[j] * phi[a[i]] % MOD * d[i][j] % MOD * inv[phi[d[i][j]]] % MOD) % MOD;
		}

		ans = (ans + f[i]) % MOD;

		// std::cout << f[i] << "\n";
		// int res = phi[a[i]];
		// std::cout << phi[a[i]] << "\n";
		// 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; 
		// 	std::cout << d[i][j] << " " << phi[d[i][j]] << " " << i << " " << j << "\n";
		// }
		// ans = (ans + res) % MOD;
		// std::cout << res << '\n';
	}

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

详细

Test #1:

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

input:

5
1 6 8 6 2

output:

700

result:

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