結果

問題 No.751 Frac #2
ユーザー uw_yu1rabbituw_yu1rabbit
提出日時 2020-08-26 19:01:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 976 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-25 03:39:02
合計ジャッジ時間 2,373 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
10,880 KB
testcase_01 AC 26 ms
10,880 KB
testcase_02 WA -
testcase_03 AC 25 ms
10,880 KB
testcase_04 RE -
testcase_05 WA -
testcase_06 WA -
testcase_07 RE -
testcase_08 WA -
testcase_09 RE -
testcase_10 WA -
testcase_11 WA -
testcase_12 RE -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 RE -
testcase_17 WA -
testcase_18 AC 26 ms
10,752 KB
testcase_19 RE -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 RE -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 RE -
testcase_32 AC 26 ms
10,880 KB
testcase_33 AC 28 ms
10,752 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

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