結果

問題 No.2829 GCD Divination
コンテスト
ユーザー ntuda
提出日時 2024-08-03 11:47:11
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
TLE  
実行時間 -
コード長 780 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 160 ms
コンパイル使用メモリ 85,240 KB
実行使用メモリ 85,036 KB
最終ジャッジ日時 2026-04-03 19:52:12
合計ジャッジ時間 5,928 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 5 TLE * 1 -- * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

def f(x):
    if x == 1:
        return 0
    P = (x / (x - 1)) ** 2
    D = make_divisors(x)
    dic = defaultdict(int)

    for d in reversed(D):
        tmp = x // d
        for d2 in reversed(D):
            if d == d2:
                break
            if d2 % d == 0:
                tmp -= dic[d2]
        dic[d] = tmp

    dic[1] = d - sum(dic.values())
    ret = 0
    for d in D[:-1]:
        ret += f(d) / x * dic[d]
    return (ret + 1) * x / (x - 1)

N = int(input())
print(f(N))
0