結果

問題 No.816 Beautiful tuples
ユーザー shotoyooshotoyoo
提出日時 2021-06-15 00:28:15
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 76 ms / 1,500 ms
コード長 573 bytes
コンパイル時間 659 ms
コンパイル使用メモリ 87,372 KB
実行使用メモリ 75,892 KB
最終ジャッジ日時 2023-08-26 14:37:08
合計ジャッジ時間 2,896 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,852 KB
testcase_01 AC 73 ms
71,800 KB
testcase_02 AC 75 ms
75,892 KB
testcase_03 AC 74 ms
75,800 KB
testcase_04 AC 74 ms
75,816 KB
testcase_05 AC 75 ms
75,528 KB
testcase_06 AC 74 ms
75,812 KB
testcase_07 AC 73 ms
75,796 KB
testcase_08 AC 73 ms
75,756 KB
testcase_09 AC 75 ms
75,796 KB
testcase_10 AC 75 ms
75,604 KB
testcase_11 AC 75 ms
75,788 KB
testcase_12 AC 73 ms
75,796 KB
testcase_13 AC 76 ms
75,796 KB
testcase_14 AC 73 ms
71,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))

### 約数列挙
def fs(n):
    s = set()
    for i in range(1,int(n**0.5)+2):
        if n%i==0:
            s.add(i)
            s.add(n//i)
    l = sorted(list(s))
    return l

a,b = list(map(int, input().split()))
l = fs(a+b)
for v in sorted(l):
    if (a+v)%b==(b+v)%a==0 and a!=v and b!=v:
        print(v)
        break
else:
    print(-1)
0