結果

問題 No.2249 GCDistance
ユーザー shobonvipshobonvip
提出日時 2023-03-17 21:56:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,955 ms / 5,000 ms
コード長 386 bytes
コンパイル時間 211 ms
コンパイル使用メモリ 81,704 KB
実行使用メモリ 232,444 KB
最終ジャッジ日時 2023-10-18 14:34:06
合計ジャッジ時間 35,461 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,424 ms
231,208 KB
testcase_01 AC 2,877 ms
232,268 KB
testcase_02 AC 2,886 ms
232,440 KB
testcase_03 AC 2,955 ms
232,444 KB
testcase_04 AC 2,592 ms
232,108 KB
testcase_05 AC 2,885 ms
232,444 KB
testcase_06 AC 2,893 ms
232,436 KB
testcase_07 AC 2,916 ms
232,232 KB
testcase_08 AC 2,473 ms
232,320 KB
testcase_09 AC 2,933 ms
232,440 KB
testcase_10 AC 2,835 ms
232,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mx = 10 ** 7

pt = [0] * (mx + 1)
euler = [1] * (mx + 1)
for i in range(2, mx + 1):
	if pt[i] == 0:
		for j in range(i, mx + 1, i):
			euler[j] *= i - 1
			k = j // i
			while k % i == 0:
				k //= i
				euler[j] *= i
			pt[j] = 1

for i in range(1, mx):
	euler[i+1] += euler[i]

T = int(input())
for _ in range(T):
	n = int(input())
	v = euler[n] - 1
	print(2*(n * (n-1) // 2 - v) + v)
0