結果

問題 No.751 Frac #2
ユーザー uw_yu1rabbit
提出日時 2020-08-26 19:01:38
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 976 bytes
コンパイル時間 376 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-11-07 13:23:18
合計ジャッジ時間 3,001 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 4 WA * 24 RE * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
def main():
    minus = 0
    n_1 = int(input())
    a = list(map(int,input().split()))
    a_top = a[0]
    a_bottom = a[1]
    for i in range(2,n_1):
        a_bottom *= a[i]
    if a_top < 0:
        a_top *= -1
        minus += 1
    if a_bottom < 0:
        a_bottom *= -1
        minus += 1
    gcd_1 = math.gcd(a_top,a_bottom)
    a_top //= gcd_1
    a_bottom //= gcd_1
    n_2 = int(input())
    b = list(map(int, input().split()))
    b_top = b[0]
    b_bottom = b[1]
    for i in range(2, n_2):
        b_bottom *= b[i]
    if b_top < 0:
        minus += 1
        b_top *= -1
    if b_bottom < 0:
        minus += 1
        b_bottom *= -1
    gcd_b = math.gcd(b_top, b_bottom)
    b_top //= gcd_b
    b_bottom //= gcd_b
    ans_top = a_top * b_bottom
    ans_bottom = b_top * a_bottom
    ans_gcd = math.gcd(ans_top,ans_bottom)
    ans_top = ans_top // ans_gcd
    ans_bottom = ans_bottom // ans_gcd
    print(ans_top * pow(-1,minus), ans_bottom)
main()
0