結果
| 問題 |
No.816 Beautiful tuples
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-04-19 22:26:14 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 31 ms / 1,500 ms |
| コード長 | 1,016 bytes |
| コンパイル時間 | 140 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 10,752 KB |
| 最終ジャッジ日時 | 2024-09-22 21:49:39 |
| 合計ジャッジ時間 | 1,324 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 |
ソースコード
from itertools import combinations
from functools import reduce
from operator import mul
from sys import stdin
def primeFactors(n):
factors = []
apnd = factors.append
while n >= 4:
if n % 2:
break
else:
n //= 2
apnd(2)
i = 3
while n >= i * i:
if n % i:
i += 2
else:
n //= i
apnd(i)
apnd(n)
return factors
def main():
A, B = map(int, input().split())
if A == B:
print(-1)
return
p = primeFactors(A + B)
if len(p) == 1:
print(-1)
else:
for i in range(1, len(p) + 1):
comb = combinations(p, i)
for j in comb:
c = reduce(mul, j)
if all((c != A,
c != B,
not (c + A) % B,
not (c + B) % A)):
print(c)
return
print(-1)
input = lambda: stdin.readline()
main()