結果

問題 No.1273 はじめのζ関数
ユーザー lam6er
提出日時 2025-04-15 22:34:48
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 636 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 82,588 KB
実行使用メモリ 65,904 KB
最終ジャッジ日時 2025-04-15 22:36:58
合計ジャッジ時間 2,884 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 39 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

x = int(input())

if x == 2:
    print(1000000)
elif x >= 20:
    # For large x, only the k=2 term is significant
    log_term = -(x - 1) * math.log(2) - math.log(1)
    term = math.exp(log_term)
    s = term
else:
    # For small x, use the partial fraction decomposition approach
    sum_zeta = math.pi ** 2 / 6  # ζ(2)
    for i in range(3, x):
        z = 1.0  # ζ(i) starts with 1 for k=1
        for k in range(2, 100000):
            term = 1.0 / (k ** i)
            if term < 1e-15:
                break
            z += term
        sum_zeta += z
    s = (x - 1) - sum_zeta

result = int(s * 1e6)
print(result)
0