結果

問題 No.816 Beautiful tuples
ユーザー GrayCoderGrayCoder
提出日時 2019-04-19 21:42:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 658 bytes
コンパイル時間 424 ms
コンパイル使用メモリ 11,980 KB
実行使用メモリ 123,776 KB
最終ジャッジ日時 2023-10-24 01:05:02
合計ジャッジ時間 3,712 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin

def erastosthenes(n):
    prime = [0, 1] * ((n + 1) // 2)
    if not n % 2:
        prime += [0]
    prime[1], prime[2] = 0, 1

    i = 3
    while i <= n ** 0.5:
        for j in range(i * i, n + 1, i):
            prime[j] = 0
        i += 2
    return prime

def main():
    A, B = map(int, input().split())

    if A == B:
        print(-1)
        return

    n = A + B
    lst = erastosthenes(n // 2)
    prime_list = [i for i in range(0, n // 2 + 1, 2) if lst[i]]
    for i in prime_list:
        if not n % i:
            print(i)
            break
    else:
        print(-1)

input = lambda: stdin.readline().rstrip()
main()
0