結果
問題 | No.2829 GCD Divination |
ユーザー | mkawa2 |
提出日時 | 2024-08-03 16:43:59 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,515 bytes |
コンパイル時間 | 536 ms |
コンパイル使用メモリ | 82,284 KB |
実行使用メモリ | 196,652 KB |
最終ジャッジ日時 | 2024-08-03 16:44:08 |
合計ジャッジ時間 | 8,702 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
55,296 KB |
testcase_01 | AC | 43 ms
54,936 KB |
testcase_02 | AC | 359 ms
192,216 KB |
testcase_03 | AC | 44 ms
55,108 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 57 ms
66,056 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 50 ms
62,872 KB |
testcase_21 | WA | - |
testcase_22 | AC | 171 ms
121,500 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 77 ms
77,872 KB |
testcase_32 | AC | 215 ms
134,768 KB |
testcase_33 | WA | - |
testcase_34 | WA | - |
ソースコード
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() 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[::-1]: if g%p==0:cnt[g]-=cnt[g//p] dp[f]=f for g in gg: dp[f]+=dp[g]*cnt[g] dp[f]/=f-1 print(dp[n])