結果
問題 | No.2249 GCDistance |
ユーザー | potoooooooo |
提出日時 | 2023-03-21 01:49:18 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,184 ms / 5,000 ms |
コード長 | 711 bytes |
コンパイル時間 | 2,138 ms |
コンパイル使用メモリ | 201,876 KB |
実行使用メモリ | 159,800 KB |
最終ジャッジ日時 | 2023-10-18 18:17:13 |
合計ジャッジ時間 | 17,595 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,098 ms
159,792 KB |
testcase_01 | AC | 1,150 ms
159,800 KB |
testcase_02 | AC | 1,154 ms
159,800 KB |
testcase_03 | AC | 1,159 ms
159,800 KB |
testcase_04 | AC | 1,114 ms
159,800 KB |
testcase_05 | AC | 1,184 ms
159,800 KB |
testcase_06 | AC | 1,164 ms
159,800 KB |
testcase_07 | AC | 1,165 ms
159,800 KB |
testcase_08 | AC | 1,103 ms
159,800 KB |
testcase_09 | AC | 1,161 ms
159,800 KB |
testcase_10 | AC | 1,136 ms
159,800 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; constexpr int max_val = 1e7; long long tot[max_val + 1]; long long ans[max_val + 1]; void solve() { for (int i = 1; i <= max_val; i++) tot[i] = i; for (int i = 2; i <= max_val; i++) { if (tot[i] == i) { tot[i]--; for (int j = i + i; j <= max_val; j += i) { tot[j] = tot[j] / i * (i - 1); } } } for (int i = 1; i < max_val; i++) { ans[i + 1] = ans[i] + i + i - tot[i + 1]; } } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int T; cin >> T; solve(); while (T--) { int n; cin >> n; cout << ans[n] << "\n"; } return 0; }