結果

問題 No.816 Beautiful tuples
ユーザー kuuso1kuuso1
提出日時 2019-04-19 22:00:29
言語 Python3
(3.10.1 + numpy 1.22.3 + scipy 1.8.0)
結果
AC  
実行時間 31 ms / 1,500 ms
コード長 717 bytes
コンパイル時間 63 ms
使用メモリ 7,944 KB
最終ジャッジ日時 2022-11-22 09:48:23
合計ジャッジ時間 1,437 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 16 ms
7,780 KB
testcase_01 AC 15 ms
7,868 KB
testcase_02 AC 18 ms
7,696 KB
testcase_03 AC 19 ms
7,944 KB
testcase_04 AC 19 ms
7,840 KB
testcase_05 AC 31 ms
7,884 KB
testcase_06 AC 21 ms
7,752 KB
testcase_07 AC 19 ms
7,720 KB
testcase_08 AC 18 ms
7,784 KB
testcase_09 AC 19 ms
7,788 KB
testcase_10 AC 25 ms
7,880 KB
testcase_11 AC 27 ms
7,724 KB
testcase_12 AC 27 ms
7,748 KB
testcase_13 AC 25 ms
7,728 KB
testcase_14 AC 16 ms
7,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
import sys
import math
##  input functions for me
def ria(sep = ''):
    if sep == '' :
        return list(map(int, input().split())) 
    else: return list(map(int, input().split(sep)))
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##

## main ##

A, B = map(int, input().split())
i = 0
l = list()
while i * i <= A + B:
    i += 1
    if (A + B) % i != 0: continue
    l.append(i)
    l.append((A + B) // i)

l.sort()
for n in l:
    if n != A and n != B and (A + n) % B == 0 and (B + n) % A == 0:
        print(n)
        sys.exit()

print(-1)

0