結果

問題 No.751 Frac #2
ユーザー ryusukeryusuke
提出日時 2022-01-27 12:23:02
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,322 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 87,216 KB
実行使用メモリ 80,576 KB
最終ジャッジ日時 2023-08-26 06:52:31
合計ジャッジ時間 6,882 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

from collections import defaultdict

def factorization(n):
    arr = []
    tmp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            arr.append([i, cnt])
    if tmp != 1:
        arr.append([tmp, 1])
    if arr == []:
        arr.append([n, 1])
    return arr

n1 = int(input())
a = list(map(int, input().split()))
n2 = int(input())
b = list(map(int, input().split()))

top = a[0] * b[-1]
down = 1
for i in a:
    down *= i

for i in b:
    down *= i
down //= (a[0] * b[-1])

f_1 = factorization(top)
f_2 = factorization(down)

d_1 = defaultdict(int)
d_2 = defaultdict(int)

for i, j in f_1:
    d_1[i] = j
for i, j in f_2:
    d_2[i] = j

ans_top = defaultdict(int)
ans_down = defaultdict(int)

for k, v in d_1.items():
    if d_2[k] == 0:
        ans_top[k] = v
    else:
        ans_top[k] = v - min(v, d_2[k])

for k, v in d_2.items():
    if d_2[k] == 0:
        ans_down[k] = v
    else:
        ans_down[k] = v - min(v, d_1[k])

'''
print(top, down)
print(f_1, f_2)
print(d_1, d_2)
print(ans_top, ans_down)
'''

multi_top, multi_down = 1, 1
for k, v in ans_top.items():
    multi_top *= k ** v

for k, v in ans_down.items():
    multi_down *= k ** v

print(multi_top, multi_down)
0