結果

問題 No.1274 楽しい格子点
ユーザー lam6er
提出日時 2025-04-16 16:41:01
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 799 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 82,336 KB
実行使用メモリ 71,820 KB
最終ジャッジ日時 2025-04-16 16:41:59
合計ジャッジ時間 3,460 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 50 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

A, B = map(int, input().split())

def compute_sum(A, B):
    if A == 0 and B == 0:
        return 0.25  # Only the initial position (1,1) is reachable
    
    d = math.gcd(abs(A), abs(B))
    if d == 0:
        return 0.25  # This case is redundant as d is at least 1 if A or B is non-zero
    
    res = 0.0
    m = 0
    while True:
        k = 2 + d * m
        term = (m + 1) / (k ** k)
        res += term
        if term < 1e-20:  # Term is small enough to stop
            break
        m += 1
    return res

result = compute_sum(A, B)
# Formatting the output to have enough decimal places and trimming trailing zeros
formatted_result = "{0:.30f}".format(result).rstrip('0').rstrip('.') if '.' in "{0:.30f}".format(result) else "{0:.30f}".format(result)
print(formatted_result)
0