結果
| 問題 | No.3687 Coprime Count |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-09-06 22:04:36 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 144 ms / 2,000 ms |
| + 590µs | |
| コード長 | 934 bytes |
| 記録 | |
| コンパイル時間 | 2,081 ms |
| コンパイル使用メモリ | 339,296 KB |
| 実行使用メモリ | 87,004 KB |
| 最終ジャッジ日時 | 2026-09-06 22:04:41 |
| 合計ジャッジ時間 | 3,586 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 |
ソースコード
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
vector<bool> isp;
vector<int> ps, pf, mu;
void sieve(int mx) {
isp.resize(mx+1);
pf.resize(mx+1);
mu.resize(mx+1);
mu[1] = 1;
rep(i, mx+1) pf[i] = i;
for (int i = 2; i <= mx; ++i) {
if (pf[i] == i) isp[i] = true, ps.push_back(i), mu[i] = -1;
rep(j, ps.size()) {
int x = ps[j]*i;
if (x > mx) break;
pf[x] = ps[j];
if (i%ps[j] == 0) {
mu[i*ps[j]] = 0;
break;
}
mu[i*ps[j]] = -mu[i];
}
}
}
int main() {
int n, m;
cin >> n >> m;
int l = min(n, m);
sieve(l);
ll ans = 0;
for (int d = 1; d <= l; ++d) {
if (mu[d] == 0) continue;
ans += (ll)mu[d]*(n/d)*(m/d);
}
cout << ans << '\n';
return 0;
}