結果
問題 | No.2829 GCD Divination |
ユーザー |
![]() |
提出日時 | 2024-08-03 11:43:02 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 130 ms / 2,000 ms |
コード長 | 846 bytes |
コンパイル時間 | 461 ms |
コンパイル使用メモリ | 82,168 KB |
実行使用メモリ | 76,672 KB |
最終ジャッジ日時 | 2024-08-03 11:43:06 |
合計ジャッジ時間 | 4,060 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 |
ソースコード
from collections import defaultdict def make_divisors(n): divisors = [] i = 1 while i ** 2 <= n: if n % i == 0: divisors.append(i) if i ** 2 != n: divisors.append(n // i) i += 1 divisors.sort() return divisors N = int(input()) D = make_divisors(N) ND = len(D) dic = defaultdict(int) for i, d in enumerate(D[1:], start=1): dic2 = defaultdict(int) D2 = make_divisors(d) S = set() for d2 in reversed(D2): tmp = d // d2 for d3 in reversed(D2): if d2 == d3: break if d3 % d2 == 0: tmp -= dic2[d3] dic2[d2] = tmp dic2[1] = d - sum(dic2.values()) tmp = 0 for d2 in D2[1:-1]: tmp += dic[d2] * dic2[d2] / d dic[d] = (tmp + 1) * d / (d - 1) print(dic[N])