結果
| 問題 | No.816 Beautiful tuples |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-04-19 22:26:14 |
| 言語 | Python3 (3.14.7 + numpy 2.5.2 + scipy 1.18.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 93 ms / 1,500 ms |
| + 510µs | |
| コード長 | 1,016 bytes |
| 記録 | |
| コンパイル時間 | 326 ms |
| コンパイル使用メモリ | 21,212 KB |
| 実行使用メモリ | 15,660 KB |
| 最終ジャッジ日時 | 2026-09-02 19:10:27 |
| 合計ジャッジ時間 | 3,184 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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()