結果

問題 No.1931 Fraction 2
ユーザー gew1fw
提出日時 2025-06-12 15:59:16
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 558 bytes
コンパイル時間 382 ms
コンパイル使用メモリ 82,364 KB
実行使用メモリ 91,928 KB
最終ジャッジ日時 2025-06-12 15:59:41
合計ジャッジ時間 5,610 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 TLE * 1 -- * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math

MOD = 998244353

def main():
    input = sys.stdin.read().split()
    ptr = 0
    N = int(input[ptr])
    ptr += 1
    current_num = 0
    current_den = 1
    for _ in range(N):
        A = int(input[ptr])
        B = int(input[ptr+1])
        ptr += 2
        new_num = current_num * B + current_den * A
        new_den = current_den * B
        g = math.gcd(new_num, new_den)
        current_num = new_num // g
        current_den = new_den // g
    print(current_num % MOD, current_den % MOD)

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