結果

問題 No.816 Beautiful tuples
ユーザー GrayCoderGrayCoder
提出日時 2019-04-19 22:26:14
言語 Python3
(3.10.1 + numpy 1.22.3 + scipy 1.8.0)
結果
AC  
実行時間 22 ms / 1,500 ms
コード長 1,016 bytes
コンパイル時間 681 ms
使用メモリ 8,192 KB
最終ジャッジ日時 2022-11-22 12:42:24
合計ジャッジ時間 1,778 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 21 ms
8,136 KB
testcase_01 AC 20 ms
8,036 KB
testcase_02 AC 21 ms
8,028 KB
testcase_03 AC 21 ms
8,192 KB
testcase_04 AC 22 ms
8,004 KB
testcase_05 AC 21 ms
8,144 KB
testcase_06 AC 20 ms
8,092 KB
testcase_07 AC 21 ms
8,132 KB
testcase_08 AC 20 ms
8,192 KB
testcase_09 AC 20 ms
8,136 KB
testcase_10 AC 20 ms
8,040 KB
testcase_11 AC 21 ms
8,096 KB
testcase_12 AC 21 ms
8,004 KB
testcase_13 AC 21 ms
8,012 KB
testcase_14 AC 20 ms
8,008 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