結果

問題 No.816 Beautiful tuples
ユーザー GrayCoderGrayCoder
提出日時 2019-04-19 22:26:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 30 ms / 1,500 ms
コード長 1,016 bytes
コンパイル時間 366 ms
コンパイル使用メモリ 11,932 KB
実行使用メモリ 10,044 KB
最終ジャッジ日時 2023-10-24 04:54:08
合計ジャッジ時間 1,690 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,044 KB
testcase_01 AC 28 ms
10,044 KB
testcase_02 AC 29 ms
10,044 KB
testcase_03 AC 29 ms
10,044 KB
testcase_04 AC 30 ms
10,044 KB
testcase_05 AC 29 ms
10,044 KB
testcase_06 AC 29 ms
10,044 KB
testcase_07 AC 29 ms
10,044 KB
testcase_08 AC 29 ms
10,044 KB
testcase_09 AC 29 ms
10,044 KB
testcase_10 AC 28 ms
10,044 KB
testcase_11 AC 29 ms
10,044 KB
testcase_12 AC 29 ms
10,044 KB
testcase_13 AC 29 ms
10,044 KB
testcase_14 AC 29 ms
10,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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()
0