結果

問題 No.816 Beautiful tuples
ユーザー tomarint2tomarint2
提出日時 2019-04-19 22:08:23
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 86 ms / 1,500 ms
コード長 473 bytes
コンパイル時間 1,081 ms
使用メモリ 80,680 KB
最終ジャッジ日時 2022-11-22 10:24:04
合計ジャッジ時間 2,981 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 82 ms
76,040 KB
testcase_01 AC 80 ms
76,276 KB
testcase_02 AC 81 ms
80,428 KB
testcase_03 AC 83 ms
80,392 KB
testcase_04 AC 86 ms
80,496 KB
testcase_05 AC 83 ms
80,608 KB
testcase_06 AC 84 ms
80,648 KB
testcase_07 AC 84 ms
80,408 KB
testcase_08 AC 81 ms
80,352 KB
testcase_09 AC 83 ms
80,532 KB
testcase_10 AC 84 ms
80,320 KB
testcase_11 AC 86 ms
80,680 KB
testcase_12 AC 84 ms
80,376 KB
testcase_13 AC 83 ms
80,376 KB
testcase_14 AC 83 ms
75,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# A+B=n*C
# B+C=m*A
# C+A=l*B
# 2 * (A+B+C) = n*C + m*A + l*B
def divisor(n):
    n2 = int((n**0.5)+1) + 1
    ret = set()
    for i in range(1,n2):
        if n%i==0:
            ret.add(i)
            ret.add(n//i)
    ret = list(ret)
    ret.sort()
    return ret

def solve():
    A,B=map(int,input().split())
    Cs=divisor(A+B)
    #print(Cs)
    for c in Cs:
        if (B+c)%A==0 and (c+A)%B==0 and A!=c and B!=c:
            return c
    return -1

print(solve())
0