結果
問題 | No.2249 GCDistance |
ユーザー | mkawa2 |
提出日時 | 2023-03-17 22:39:30 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 3,667 ms / 5,000 ms |
コード長 | 2,115 bytes |
コンパイル時間 | 898 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 318,568 KB |
最終ジャッジ日時 | 2024-09-26 05:58:30 |
合計ジャッジ時間 | 46,864 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3,516 ms
318,400 KB |
testcase_01 | AC | 3,627 ms
318,004 KB |
testcase_02 | AC | 3,611 ms
318,460 KB |
testcase_03 | AC | 3,667 ms
318,448 KB |
testcase_04 | AC | 3,532 ms
317,896 KB |
testcase_05 | AC | 3,570 ms
318,080 KB |
testcase_06 | AC | 3,589 ms
318,568 KB |
testcase_07 | AC | 3,621 ms
318,224 KB |
testcase_08 | AC | 3,509 ms
318,440 KB |
testcase_09 | AC | 3,599 ms
318,136 KB |
testcase_10 | AC | 3,581 ms
317,928 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = (1 << 63)-1 # inf = (1 << 31)-1 # md = 10**9+7 # md = 998244353 class Sieve: def __init__(self, n): self.plist = [2] min_prime_factor = [2, 0]*(n//2+1) for x in range(3, n+1, 2): if min_prime_factor[x] == 0: min_prime_factor[x] = x self.plist.append(x) if x**2 > n: continue for y in range(x**2, n+1, 2*x): if min_prime_factor[y] == 0: min_prime_factor[y] = x self.min_prime_factor = min_prime_factor def isprime(self, x): return self.min_prime_factor[x] == x def pf(self, x): pp, ee = [], [] while x > 1: mpf = self.min_prime_factor[x] if pp and mpf == pp[-1]: ee[-1] += 1 else: pp.append(mpf) ee.append(1) x //= mpf return pp, ee # unsorted def factor(self, a): ff = [1] pp, ee = self.pf(a) for p, e in zip(pp, ee): ff, gg = [], ff w = p for _ in range(e): for f in gg: ff.append(f*w) w *= p ff += gg return ff mx = 10**7 sv = Sieve(mx) ans = [0, 0, 1]+[0]*mx for a in range(3, mx+1): pp, _ = sv.pf(a) x = a for p in pp: x = x*(p-1)//p ans[a] = ans[a-1]-x+(a-1)*2 # print(ans) for _ in range(II()): print(ans[II()])