結果
| 問題 |
No.2249 GCDistance
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-03-17 21:45:09 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 2,908 ms / 5,000 ms |
| コード長 | 978 bytes |
| コンパイル時間 | 207 ms |
| コンパイル使用メモリ | 82,196 KB |
| 実行使用メモリ | 234,240 KB |
| 最終ジャッジ日時 | 2024-09-18 10:34:35 |
| 合計ジャッジ時間 | 31,255 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 10 |
ソースコード
#ごめんなさいpypy遅くないです
import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import gcd,log
input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())
def brute(N):
res = 0
for i in range(1,N+1):
for j in range(i+1,N+1):
if gcd(i,j) == 1:
res += 1
return res
M = 10**7
mebius = [1] * (M+1)
phi = [i for i in range(M+1)]
for p in range(2,M+1):
if phi[p] == p:
for k in range(p,M+1,p):
mebius[k] *= -1
t = p*p
for k in range(t,M+1,t):
mebius[k] = 0
if mebius[p]!=0:
t = mebius[p]
for q in range(1,M//p+1):
phi[q*p] += t * q
for i in range(1,M+1):
phi[i] += phi[i-1]
for _ in range(int(input())):
N = int(input())
res = N*(N-1) - (phi[N]-1)
print(res)