結果
| 問題 |
No.2249 GCDistance
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-03-18 00:02:11 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,250 ms / 5,000 ms |
| コード長 | 647 bytes |
| コンパイル時間 | 1,888 ms |
| コンパイル使用メモリ | 192,276 KB |
| 最終ジャッジ日時 | 2025-02-11 14:37:13 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 10 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
typedef long long ll;
int main() {
cin.tie(0); ios::sync_with_stdio(false);
int MAX = 10000010;
ll phi[MAX];
rep(i, MAX) phi[i] = (ll)(i);
for (int i=2; i<MAX; i++) {
if (phi[i]==i) {
for (int j=i; j<MAX; j+=i) {
phi[j] = phi[j]/i*(i-1);
}
}
}
for (int i=1; i<MAX; i++) phi[i] += phi[i-1];
int T; cin >> T;
while (T--) {
int N; cin >> N;
ll ans = (ll)(N)*(N-1)-phi[N]+1;
printf("%lld\n", ans);
}
}