結果

問題 No.2249 GCDistance
ユーザー 👑 timitimi
提出日時 2023-03-22 13:45:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,861 ms / 5,000 ms
コード長 338 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 81,712 KB
実行使用メモリ 154,576 KB
最終ジャッジ日時 2023-10-18 18:59:03
合計ジャッジ時間 22,183 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,336 ms
153,484 KB
testcase_01 AC 1,822 ms
154,576 KB
testcase_02 AC 1,830 ms
154,572 KB
testcase_03 AC 1,826 ms
154,572 KB
testcase_04 AC 1,531 ms
154,572 KB
testcase_05 AC 1,812 ms
154,572 KB
testcase_06 AC 1,820 ms
154,572 KB
testcase_07 AC 1,861 ms
154,576 KB
testcase_08 AC 1,368 ms
154,452 KB
testcase_09 AC 1,810 ms
154,576 KB
testcase_10 AC 1,753 ms
154,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

M=10**7+1
#calculate φ(x) for 1<= x<= M 累積和
phi=list(range(M+1))
for x in range(2, M+1):
  if phi[x]==x:
    for y in range(x, M+1, x):
      phi[y]=phi[y]//x*(x-1)
for x in range(2,M+1):
    phi[x]+=phi[x-1] 
#print(phi[:10])
T=int(input())
for _ in range(T):
  S=int(input())
  a,b=S*(S-1)//2,phi[S]-1
  c=a-b
  print(b+2*c)
  
0