結果
問題 | No.2249 GCDistance |
ユーザー |
|
提出日時 | 2023-03-22 05:02:03 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 586 ms / 5,000 ms |
コード長 | 727 bytes |
コンパイル時間 | 1,602 ms |
コンパイル使用メモリ | 168,980 KB |
実行使用メモリ | 159,488 KB |
最終ジャッジ日時 | 2024-09-18 14:42:32 |
合計ジャッジ時間 | 9,917 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 10 |
ソースコード
#include <bits/stdc++.h>using namespace std;const int MX = 1E7 + 5;int main() {ios_base::sync_with_stdio(false);cin.tie(nullptr);vector<int> pr(MX), phi(MX);phi[1] = 1;vector<long long> ans(MX);for (int i = 2; i < MX; i++) {if (pr[i] == 0) {pr[i] = i;for (int j = i; j <= (MX - 1) / i; j++) {pr[i * j] = i;}}int t = i, p = pr[i];while (t % p == 0) {t /= p;}phi[i] = phi[t] * (i / t) / p * (p - 1);ans[i] = ans[i - 1] + phi[i] + (i - 1 - phi[i]) * 2;}int t; cin >> t;while (t--) {int u; cin >> u;cout << ans[u] << '\n';}}