結果

問題 No.2829 GCD Divination
ユーザー ntuda
提出日時 2024-08-03 12:10:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 781 bytes
コンパイル時間 358 ms
コンパイル使用メモリ 82,108 KB
実行使用メモリ 76,864 KB
最終ジャッジ日時 2024-08-03 12:10:11
合計ジャッジ時間 3,589 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
dic = defaultdict(int)
for i, d in enumerate(D[1:], start=1):
    dic2 = defaultdict(int)
    D2 = make_divisors(d)
    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

    tmp = 0
    for d2 in D2[1:-1]:
        tmp += dic[d2] * dic2[d2] / d
    dic[d] = (tmp + 1) * d / (d - 1)

print(dic[N])
0