結果

問題 No.2249 GCDistance
ユーザー kotatsugame
提出日時 2023-03-17 21:58:51
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,475 ms / 5,000 ms
コード長 399 bytes
コンパイル時間 502 ms
コンパイル使用メモリ 65,552 KB
実行使用メモリ 91,412 KB
最終ジャッジ日時 2024-09-18 10:52:21
合計ジャッジ時間 18,336 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

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