結果

問題 No.2249 GCDistance
ユーザー chineristACchineristAC
提出日時 2023-03-17 21:29:36
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 906 bytes
コンパイル時間 155 ms
コンパイル使用メモリ 81,644 KB
実行使用メモリ 237,360 KB
最終ジャッジ日時 2023-10-18 13:58:41
合計ジャッジ時間 13,652 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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
            if k%(p*p) == 0:
                mebius[k] = 0
    if mebius[p]!=0:
        for k in range(p,M+1,p):
            phi[k] += mebius[p] * (k//p)

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)
0