QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#736854 | #9619. 乘积,欧拉函数,求和 | fsy_juruo | WA | 1ms | 3776kb | C++17 | 1.3kb | 2024-11-12 13:41:40 | 2024-11-12 13:41:40 |
Judging History
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'