結果

問題 No.751 Frac #2
ユーザー ああいい
提出日時 2022-05-29 20:11:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 40 ms / 1,000 ms
コード長 435 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 82,164 KB
実行使用メモリ 52,480 KB
最終ジャッジ日時 2024-09-21 00:38:20
合計ジャッジ時間 2,824 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
A = list(map(int,input().split()))
m = int(input())
B = list(map(int,input().split()))

def gcd(a,b):
    while True:
        r = a % b
        a = b
        b = r
        if r == 0:
            return a
si = A[0]
bo = 1
for a in A[1:]:
    bo *= a
for i in range(0,m,2):
    bo *= B[i]
for i in range(1,m,2):
    si *= B[i]
d = gcd(abs(si),abs(bo))
si //= d
bo //= d
if bo < 0:
    si *= -1
    bo *= -1
print(si,bo)
0