結果
| 問題 |
No.2249 GCDistance
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-03-17 21:29:36 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 906 bytes |
| コンパイル時間 | 297 ms |
| コンパイル使用メモリ | 81,920 KB |
| 実行使用メモリ | 238,464 KB |
| 最終ジャッジ日時 | 2024-09-18 10:16:36 |
| 合計ジャッジ時間 | 13,274 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | TLE * 1 |
| other | TLE * 6 -- * 4 |
ソースコード
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)