結果

問題 No.2249 GCDistance
ユーザー kotatsugamekotatsugame
提出日時 2023-03-17 21:58:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,451 ms / 5,000 ms
コード長 399 bytes
コンパイル時間 860 ms
コンパイル使用メモリ 65,364 KB
実行使用メモリ 91,604 KB
最終ジャッジ日時 2023-10-18 14:36:28
合計ジャッジ時間 19,091 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,079 ms
91,604 KB
testcase_01 AC 1,451 ms
91,604 KB
testcase_02 AC 1,436 ms
91,604 KB
testcase_03 AC 1,442 ms
91,604 KB
testcase_04 AC 1,211 ms
91,604 KB
testcase_05 AC 1,440 ms
91,604 KB
testcase_06 AC 1,444 ms
91,604 KB
testcase_07 AC 1,442 ms
91,604 KB
testcase_08 AC 1,091 ms
91,604 KB
testcase_09 AC 1,439 ms
91,604 KB
testcase_10 AC 1,403 ms
91,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;
const int N=1e7;
long phi[N+1];
bool isp[N+1];
int main()
{
	for(int i=1;i<=N;i++)
	{
		phi[i]=i;
		isp[i]=true;
	}
	for(int p=2;p<=N;p++)if(isp[p])
	{
		for(int i=p;i<=N;i+=p)
		{
			phi[i]=phi[i]/p*(p-1);
			isp[i]=false;
		}
	}
	for(int i=1;i<N;i++)phi[i+1]+=phi[i];
	int T;cin>>T;
	for(;T--;)
	{
		int n;cin>>n;
		cout<<(long)n*(n-1)-phi[n]+1<<"\n";
	}
}
0