結果
| 問題 |
No.751 Frac #2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-10-19 14:45:34 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,158 bytes |
| コンパイル時間 | 275 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 10,752 KB |
| 最終ジャッジ日時 | 2024-06-29 17:34:48 |
| 合計ジャッジ時間 | 2,673 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 9 WA * 27 |
ソースコード
from functools import reduce
from operator import mul
def positive_gcd(*numbers: int) -> int:
numbers = list(map(abs, numbers))
if len(numbers) == 1:
return numbers[0]
if len(numbers) == 2:
a, b = numbers
if a < b:
a, b = b, a
while True:
if a % b == 0:
return b
a, b = b, a % b
first_gcd = positive_gcd(*numbers[:2])
return positive_gcd(first_gcd, *numbers[2:])
def main():
n1 = int(input())
A = list(map(int, input().split()))
n2 = int(input())
B = list(map(int, input().split()))
A_child = A[0]
if n1 == 1:
A_parent = 1
else:
A_parent = reduce(mul, A[1:])
B_child = B[0]
if n2 == 1:
B_parent = 1
else:
B_parent = reduce(mul, B[1:])
AB_child = A_child * B_parent
AB_parent = A_parent * B_child
gcd = positive_gcd(AB_child, AB_parent)
AB_child //= gcd
AB_parent //= gcd
if AB_child * AB_parent < 0:
print(-1 * abs(AB_child), abs(AB_parent))
else:
print(abs(AB_child), abs(AB_parent))
if __name__ == "__main__":
main()