結果

問題 No.2552 Not Coprime, Not Divisor
ユーザー cho435cho435
提出日時 2023-12-05 23:15:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 643 ms / 2,000 ms
コード長 438 bytes
コンパイル時間 2,717 ms
コンパイル使用メモリ 201,512 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-05 23:15:56
合計ジャッジ時間 10,475 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 215 ms
6,676 KB
testcase_01 AC 464 ms
6,676 KB
testcase_02 AC 173 ms
6,676 KB
testcase_03 AC 457 ms
6,676 KB
testcase_04 AC 459 ms
6,676 KB
testcase_05 AC 53 ms
6,676 KB
testcase_06 AC 518 ms
6,676 KB
testcase_07 AC 593 ms
6,676 KB
testcase_08 AC 369 ms
6,676 KB
testcase_09 AC 643 ms
6,676 KB
testcase_10 AC 150 ms
6,676 KB
testcase_11 AC 307 ms
6,676 KB
testcase_12 AC 605 ms
6,676 KB
testcase_13 AC 194 ms
6,676 KB
testcase_14 AC 116 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 92 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 3 ms
6,676 KB
testcase_25 AC 3 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int totient(int x){
	int ret = x;
	for(int p=2;p*p<=x;p++){
		if(x%p==0){
			ret -= ret/p;
			while(x%p==0) x/=p;
		}
	}
	if(x!=1) ret -= ret/x;
	return ret;
}

int main(){
	ll n;
	cin>>n;
	ll ans=0;
	ans+=n*(n-1)/2;
	for(int i=2;i<=n;i++){
		ans-=totient(i);
	}
	for(int i=2;i<=n;i++){
		ans-=n/i-1;
	}
	cout<<ans<<endl;
}
0