結果

問題 No.2249 GCDistance
ユーザー 👑 colognecologne
提出日時 2023-03-21 14:06:59
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,162 ms / 5,000 ms
コード長 469 bytes
コンパイル時間 3,334 ms
コンパイル使用メモリ 244,324 KB
実行使用メモリ 81,668 KB
最終ジャッジ日時 2023-10-18 18:25:31
合計ジャッジ時間 19,205 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,092 ms
81,660 KB
testcase_01 AC 1,155 ms
81,668 KB
testcase_02 AC 1,149 ms
81,668 KB
testcase_03 AC 1,153 ms
81,668 KB
testcase_04 AC 1,117 ms
81,668 KB
testcase_05 AC 1,153 ms
81,668 KB
testcase_06 AC 1,161 ms
81,668 KB
testcase_07 AC 1,160 ms
81,668 KB
testcase_08 AC 1,112 ms
81,668 KB
testcase_09 AC 1,162 ms
81,668 KB
testcase_10 AC 1,150 ms
81,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int MAX = 10'000'000;
long long phi[MAX + 1];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	iota(phi, phi + MAX + 1, 0);
	phi[1] = 0;
	for (int i = 2; i <= MAX; ++i)
	{
		if (phi[i] == i)
			for (int j = 1; i * j <= MAX; ++j)
				phi[i * j] -= phi[i * j] / i;
		phi[i] = 2 * (i - 1) - phi[i];
		phi[i] += phi[i - 1];
	}
	int T;
	cin >> T;
	while (T--)
	{
		int N;
		cin >> N;
		cout << phi[N] << '\n';
	}
}
0