結果
| 問題 |
No.2249 GCDistance
|
| コンテスト | |
| ユーザー |
merom686
|
| 提出日時 | 2023-03-18 01:36:43 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 347 ms / 5,000 ms |
| コード長 | 598 bytes |
| コンパイル時間 | 1,833 ms |
| コンパイル使用メモリ | 192,840 KB |
| 最終ジャッジ日時 | 2025-02-11 14:45:48 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 10 |
ソースコード
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
constexpr int M = 1e7;
int a[M + 1];
ll s[M + 1];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
for (int i = 2; i <= M; i++) {
a[i] = i;
}
for (int i = 2; i <= M; i++) {
if (i == a[i]) {
for (int j = i; j <= M; j += i) {
a[j] = a[j] / i * (i - 1);
}
}
s[i] = s[i - 1] + (i - 1) * 2 - a[i];
}
while (t--) {
int n;
cin >> n;
cout << s[n] << '\n';
}
return 0;
}
merom686