結果

問題 No.751 Frac #2
ユーザー hedwig100
提出日時 2020-04-26 10:59:28
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 1,260 bytes
コンパイル時間 403 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-11-16 03:39:39
合計ジャッジ時間 2,538 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

INF = 10 ** 9
MOD = 10 **9 + 7
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from math import gcd

def main():
    n = int(input())
    a = list(map(int,input().split()))
    m = int(input())
    b = list(map(int,input().split()))

    if n%2 == 0:
        child = a[0]
        mother = 1
        for i in range(1,n):
            mother *= a[i]
        for i in range(m):
            if m%2 == 0:
                child *= b[i]
            else:
                mother *= b[i]
        if child < 0 and mother < 0:
            child *= -1
            mother *= -1
        elif child > 0 and mother < 0:
            child *= -1
            mother *= -1
        g = gcd(child,mother)
        print(child//g,mother//g)
    
    else:
        child = a[0]
        mother = 1
        for i in range(1,n):
            mother *= a[i]
        for i in range(m):
            if i%2 == 0:
                mother *= b[i]
            else:
                child *= b[i]
        if child < 0 and mother < 0:
            child *= -1
            mother *= -1
        elif child > 0 and mother < 0:
            child *= -1
            mother *= -1
        g = gcd(child,mother)
        print(child//g,mother//g)

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