結果

問題 No.2829 GCD Divination
ユーザー KudeKude
提出日時 2024-08-02 21:47:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 597 bytes
コンパイル時間 333 ms
コンパイル使用メモリ 82,460 KB
実行使用メモリ 57,784 KB
最終ジャッジ日時 2024-08-02 21:47:06
合計ジャッジ時間 2,507 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
53,352 KB
testcase_01 AC 34 ms
53,072 KB
testcase_02 AC 37 ms
57,784 KB
testcase_03 AC 33 ms
52,624 KB
testcase_04 AC 33 ms
52,684 KB
testcase_05 AC 34 ms
53,716 KB
testcase_06 AC 35 ms
53,884 KB
testcase_07 AC 35 ms
52,152 KB
testcase_08 AC 38 ms
53,848 KB
testcase_09 AC 33 ms
52,800 KB
testcase_10 AC 35 ms
52,984 KB
testcase_11 AC 33 ms
52,888 KB
testcase_12 AC 34 ms
52,188 KB
testcase_13 AC 34 ms
52,128 KB
testcase_14 AC 36 ms
52,376 KB
testcase_15 AC 33 ms
52,832 KB
testcase_16 AC 34 ms
52,568 KB
testcase_17 AC 34 ms
52,392 KB
testcase_18 AC 35 ms
52,396 KB
testcase_19 AC 34 ms
53,348 KB
testcase_20 AC 36 ms
53,324 KB
testcase_21 AC 36 ms
52,812 KB
testcase_22 AC 37 ms
57,336 KB
testcase_23 AC 35 ms
52,864 KB
testcase_24 AC 37 ms
52,684 KB
testcase_25 AC 35 ms
53,380 KB
testcase_26 AC 36 ms
53,244 KB
testcase_27 AC 36 ms
53,780 KB
testcase_28 AC 34 ms
52,264 KB
testcase_29 AC 34 ms
52,988 KB
testcase_30 AC 34 ms
52,616 KB
testcase_31 AC 34 ms
52,284 KB
testcase_32 AC 35 ms
52,072 KB
testcase_33 AC 34 ms
52,772 KB
testcase_34 AC 32 ms
53,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def factorize(x):
    ret = []
    p = 2
    while p * p <= x:
        cnt = 0
        while x % p == 0:
            x //= p
            cnt += 1
        if cnt:
            ret.append(p)
        p += 1
    if x > 1:
        ret.append(x)
    return ret

n = int(input())
ps = factorize(n)
k = len(ps)
ans = 1
for s in range(1, 1 << k):
    p = 1
    for i in range(k):
        if s >> i & 1:
            p *= ps[i]
    cnt = n // p
    # p = cnt / n
    # p/(1-p) = cnt / (n - cnt)
    v = cnt / (n - cnt)
    if s.bit_count() % 2:
        ans += v
    else:
        ans -= v
print(f'{ans:.12f}')
0