結果

問題 No.816 Beautiful tuples
ユーザー tcltktcltk
提出日時 2022-06-03 03:51:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 123 ms / 1,500 ms
コード長 898 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 81,796 KB
実行使用メモリ 86,396 KB
最終ジャッジ日時 2023-10-21 01:25:19
合計ジャッジ時間 3,452 ms
ジャッジサーバーID
(参考情報)
judge13 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
86,140 KB
testcase_01 AC 118 ms
86,140 KB
testcase_02 AC 119 ms
86,396 KB
testcase_03 AC 114 ms
86,392 KB
testcase_04 AC 114 ms
86,384 KB
testcase_05 AC 115 ms
86,392 KB
testcase_06 AC 123 ms
86,388 KB
testcase_07 AC 123 ms
86,392 KB
testcase_08 AC 119 ms
86,392 KB
testcase_09 AC 112 ms
86,392 KB
testcase_10 AC 114 ms
86,388 KB
testcase_11 AC 114 ms
86,392 KB
testcase_12 AC 118 ms
86,392 KB
testcase_13 AC 115 ms
86,392 KB
testcase_14 AC 117 ms
86,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


# sys.setrecursionlimit(1000000)

# _INPUT = """# paste here...
# """
# sys.stdin = io.StringIO(_INPUT)

INF = 10**10

def get_divisors(n):
    lower_divisors = []
    upper_divisors = []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

# def solve(A: int, B: int) -> int:
def solve(A, B):
    s = A+B
    divs = get_divisors(s)
    for d in divs:
        if d != A and d != B and (A+d) % B == 0 and (B+d) % A == 0:
            return d
    return -1



A, B = map(int, input().split())
print(solve(A, B))
0