結果

問題 No.2249 GCDistance
ユーザー cologne
提出日時 2023-03-21 14:06:59
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,167 ms / 5,000 ms
コード長 469 bytes
コンパイル時間 2,614 ms
コンパイル使用メモリ 242,952 KB
実行使用メモリ 81,676 KB
最終ジャッジ日時 2024-09-18 14:21:50
合計ジャッジ時間 16,599 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

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