結果
| 問題 | No.3686 Coprime Sum |
| コンテスト | |
| ユーザー |
hiromi_ayase
|
| 提出日時 | 2026-09-12 06:59:32 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
TLE
不安定
|
| 実行時間 | - |
| コード長 | 1,165 bytes |
| 記録 | |
| コンパイル時間 | 4,772 ms |
| コンパイル使用メモリ | 375,528 KB |
| 実行使用メモリ | 43,776 KB |
| 最終ジャッジ日時 | 2026-09-12 06:59:52 |
| 合計ジャッジ時間 | 18,952 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 TLE * 1 |
| other | AC * 10 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define FAST_IO \
ios::sync_with_stdio(false); \
cin.tie(0);
const i64 INF = 1001001001001001001;
using Modint = atcoder::static_modint<998244353>;
int main() {
FAST_IO
int N, M;
cin >> N >> M;
// gcd(a, b) = 1 sum(ab)
// d|gcd(a,b) sum(ab * sum(mu(d)))
// d|a, d|b sum(ab * sum(mu(d)))
vector<int> mu(max(N, M) + 1, 1);
mu[0] = 0;
vector<bool> is_prime(N + 1, true);
for (int i = 2; i <= N; i ++) {
if (is_prime[i]) {
if (1LL * i * i <= N) {
for (int j = i * i; j <= N; j += i * i) {
mu[j] = 0;
}
}
for (int j = i; j <= N; j += i) {
is_prime[j] = false;
mu[j] *= -1;
}
}
}
Modint ans = 0;
for (int d = 1; d <= min(N, M); d ++) {
i64 p = N / d;
i64 q = M / d;
// (d + 2d + ... + pd) * (d + ... + qd)
auto ps = Modint(1) * d * p * (p + 1) / 2;
auto qs = Modint(1) * d * q * (q + 1) / 2;
ans += ps * qs * mu[d];
}
cout << ans.val() << endl;
}
hiromi_ayase