結果
| 問題 | No.3687 Coprime Count |
| コンテスト | |
| ユーザー |
hiromi_ayase
|
| 提出日時 | 2026-09-12 06:46:52 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 225 ms / 2,000 ms |
| + 384µs | |
| コード長 | 982 bytes |
| 記録 | |
| コンパイル時間 | 4,269 ms |
| コンパイル使用メモリ | 375,000 KB |
| 実行使用メモリ | 43,648 KB |
| 最終ジャッジ日時 | 2026-09-12 06:47:00 |
| 合計ジャッジ時間 | 6,439 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| 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;
// d|gcd(a,b) sum(mu(d))
// d|a and d|b sum(mu(d))
// d=1,... a=dp, b=dq 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;
}
}
}
i64 ans = 0;
for (int d = 1; d <= min(N, M); d ++) {
ans += 1LL * (N/d) * (M/d) * mu[d];
}
cout << ans << endl;
}
hiromi_ayase