結果
| 問題 |
No.2249 GCDistance
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-03-21 19:14:34 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 246 ms / 5,000 ms |
| コード長 | 1,005 bytes |
| コンパイル時間 | 2,930 ms |
| コンパイル使用メモリ | 248,520 KB |
| 実行使用メモリ | 162,292 KB |
| 最終ジャッジ日時 | 2024-09-18 14:27:55 |
| 合計ジャッジ時間 | 6,834 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| 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;
// totient table
vector<int> ps, pf, phi;
void sieve(int mx) {
pf.resize(mx+1);
phi.resize(mx+1);
phi[1] = 1;
rep(i, mx+1) pf[i] = i;
for (int i = 2; i <= mx; ++i) {
if (pf[i] == i) {
ps.push_back(i);
phi[i] = i-1;
}
rep(j, ps.size()) {
int x = ps[j]*i;
if (x > mx) break;
pf[x] = ps[j];
if (i%ps[j] == 0) {
phi[x] = phi[i]*ps[j];
break;
}
phi[x] = phi[i]*(ps[j]-1);
}
}
}
int main() {
sieve(1e7);
vector<ll> s(1e7+1);
rep(i, 1e7) s[i+1] = s[i]+phi[i+1];
cin.tie(nullptr) -> sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
ll ans = (ll)n*(n-1) - s[n] + 1;
cout << ans << '\n';
}
return 0;
}