結果
問題 | No.2829 GCD Divination |
ユーザー | mkawa2 |
提出日時 | 2024-08-03 16:47:59 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 313 ms / 2,000 ms |
コード長 | 2,546 bytes |
コンパイル時間 | 397 ms |
コンパイル使用メモリ | 82,468 KB |
実行使用メモリ | 195,524 KB |
最終ジャッジ日時 | 2024-08-03 16:48:07 |
合計ジャッジ時間 | 7,756 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
55,716 KB |
testcase_01 | AC | 39 ms
54,584 KB |
testcase_02 | AC | 311 ms
190,228 KB |
testcase_03 | AC | 37 ms
55,628 KB |
testcase_04 | AC | 313 ms
195,524 KB |
testcase_05 | AC | 302 ms
186,052 KB |
testcase_06 | AC | 261 ms
170,044 KB |
testcase_07 | AC | 248 ms
159,944 KB |
testcase_08 | AC | 202 ms
133,176 KB |
testcase_09 | AC | 155 ms
121,168 KB |
testcase_10 | AC | 201 ms
138,180 KB |
testcase_11 | AC | 49 ms
65,924 KB |
testcase_12 | AC | 79 ms
88,064 KB |
testcase_13 | AC | 276 ms
178,060 KB |
testcase_14 | AC | 192 ms
142,352 KB |
testcase_15 | AC | 173 ms
120,540 KB |
testcase_16 | AC | 92 ms
91,844 KB |
testcase_17 | AC | 70 ms
77,684 KB |
testcase_18 | AC | 64 ms
74,440 KB |
testcase_19 | AC | 76 ms
82,284 KB |
testcase_20 | AC | 44 ms
62,512 KB |
testcase_21 | AC | 120 ms
111,112 KB |
testcase_22 | AC | 152 ms
121,788 KB |
testcase_23 | AC | 175 ms
134,676 KB |
testcase_24 | AC | 255 ms
164,328 KB |
testcase_25 | AC | 295 ms
188,700 KB |
testcase_26 | AC | 151 ms
116,868 KB |
testcase_27 | AC | 225 ms
158,656 KB |
testcase_28 | AC | 76 ms
83,888 KB |
testcase_29 | AC | 142 ms
121,660 KB |
testcase_30 | AC | 309 ms
185,008 KB |
testcase_31 | AC | 70 ms
78,052 KB |
testcase_32 | AC | 187 ms
134,144 KB |
testcase_33 | AC | 133 ms
115,440 KB |
testcase_34 | AC | 234 ms
154,636 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) # sys.set_int_max_str_digits(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-(-1 << 31) inf = -1-(-1 << 62) # 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 from collections import defaultdict n=II() sv=Sieve(n) pp,ee=sv.pf(n) ff = [1] 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 ff.sort() # print(ff) dp=defaultdict(int) for i,f in enumerate(ff[1:],1): cnt=defaultdict(int) gg=[] for g in ff[1:i]: if f%g==0: cnt[g]=f//g-1 gg.append(g) for p in pp: for g in gg: if g%p==0:cnt[g//p]-=cnt[g] dp[f]=f for g in gg: dp[f]+=dp[g]*cnt[g] dp[f]/=f-1 # print(f,gg,cnt,dp) print(dp[n])