結果
問題 | No.2829 GCD Divination |
ユーザー | detteiuu |
提出日時 | 2024-08-10 02:51:45 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 191 ms / 2,000 ms |
コード長 | 2,345 bytes |
コンパイル時間 | 514 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 92,836 KB |
最終ジャッジ日時 | 2024-08-10 02:51:52 |
合計ジャッジ時間 | 6,595 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
52,864 KB |
testcase_01 | AC | 38 ms
53,120 KB |
testcase_02 | AC | 125 ms
82,688 KB |
testcase_03 | AC | 38 ms
52,480 KB |
testcase_04 | AC | 143 ms
89,728 KB |
testcase_05 | AC | 191 ms
92,836 KB |
testcase_06 | AC | 191 ms
92,416 KB |
testcase_07 | AC | 185 ms
92,472 KB |
testcase_08 | AC | 189 ms
92,556 KB |
testcase_09 | AC | 184 ms
92,772 KB |
testcase_10 | AC | 156 ms
83,328 KB |
testcase_11 | AC | 66 ms
66,176 KB |
testcase_12 | AC | 129 ms
82,944 KB |
testcase_13 | AC | 125 ms
82,816 KB |
testcase_14 | AC | 128 ms
82,944 KB |
testcase_15 | AC | 141 ms
83,328 KB |
testcase_16 | AC | 133 ms
82,688 KB |
testcase_17 | AC | 130 ms
83,456 KB |
testcase_18 | AC | 108 ms
78,464 KB |
testcase_19 | AC | 147 ms
82,688 KB |
testcase_20 | AC | 47 ms
61,944 KB |
testcase_21 | AC | 136 ms
83,456 KB |
testcase_22 | AC | 130 ms
82,944 KB |
testcase_23 | AC | 150 ms
87,552 KB |
testcase_24 | AC | 129 ms
83,072 KB |
testcase_25 | AC | 140 ms
82,432 KB |
testcase_26 | AC | 131 ms
82,816 KB |
testcase_27 | AC | 160 ms
83,328 KB |
testcase_28 | AC | 130 ms
82,816 KB |
testcase_29 | AC | 127 ms
83,072 KB |
testcase_30 | AC | 128 ms
83,200 KB |
testcase_31 | AC | 129 ms
83,200 KB |
testcase_32 | AC | 128 ms
82,688 KB |
testcase_33 | AC | 131 ms
83,328 KB |
testcase_34 | AC | 133 ms
83,072 KB |
ソースコード
import sys sys.setrecursionlimit(10**6) import pypyjit pypyjit.set_param('max_unroll_recursion=-1') class Eratosthenes: def __init__(self, n): self.isPrime = [True]*(n+1) self.minfactor = [-1]*(n+1) self.isPrime[0], self.isPrime[1] = False, False self.minfactor[1] = 1 for i in range(2, n+1): if self.isPrime[i]: self.minfactor[i] = i for j in range(i*2, n+1, i): self.isPrime[j] = False if self.minfactor[j] == -1: self.minfactor[j] = i def factorize(self, n): factor = [] while n > 1: p = self.minfactor[n] cnt = 0 while self.minfactor[n] == p: n //= p cnt += 1 factor.append((p, cnt)) return factor def divisor(self, n): ans = [1] pf = self.factorize(n) for p, c in pf: L = len(ans) for i in range(L): v = 1 for _ in range(c): v *= p ans.append(ans[i]*v) return sorted(ans) def factorization2(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i == 0: cnt = 0 while temp%i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr def Euler(n): if n > 10**6: fact = factorization2(n) else: fact = E.factorize(n) ans = n for n, c in fact: ans *= 1-(1/n) return ans def divisor2(n): ans = [] for i in range(1, int(n**0.5)+1): if n % i == 0: ans.append(i) if i*i != n: ans.append(n//i) return sorted(ans) N = int(input()) def dfs(n): if n in D: return D[n] if n > 10**6: div = divisor2(n) else: div = E.divisor(n) cnt = [0]*(len(div)-2) for i in range(len(div)-2): cnt[i] = Euler(n//div[i+1]) SUM = 0 for i in range(len(cnt)): SUM += dfs(div[i+1])*(cnt[i]/(n-1)) D[n] = SUM+n/(n-1) return D[n] E = Eratosthenes(min(10**6, N)) D = dict() print(dfs(N))