結果

問題 No.1278 どんな級数?
ユーザー lam6er
提出日時 2025-03-31 17:52:42
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 974 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 82,540 KB
実行使用メモリ 71,364 KB
最終ジャッジ日時 2025-03-31 17:53:59
合計ジャッジ時間 23,943 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 9 WA * 28 RE * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def main():
    X, K = map(int, sys.stdin.readline().split())
    if X == 1:
        print("{0:.10f}".format(0.75))
    else:
        result = 0.0
        for s in range(2, K + 1):
            if s <= 20:
                term = 0.0
                k = 2
                while True:
                    add = 1.0 / (k ** s)
                    term += add
                    if add < 1e-15 * term or add < 1e-20:
                        break
                    k += 1
            else:
                # Approximation for s > 20
                term = 1.0 / (2 ** s) + 1.0 / (3 ** s)
                # Check if 4^s term is needed (unlikely)
                if s <= 30:
                    add = 1.0 / (4 ** s)
                    term += add
                    add = 1.0 / (5 ** s)
                    if add > 1e-20:
                        term += add
            result += term
        print("{0:.9f}".format(result))

if __name__ == '__main__':
    main()
0