結果

問題 No.726 Tree Game
ユーザー tktk_snsntktk_snsn
提出日時 2021-01-01 15:52:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 831 bytes
コンパイル時間 133 ms
コンパイル使用メモリ 82,496 KB
実行使用メモリ 61,968 KB
最終ジャッジ日時 2024-04-19 12:24:59
合計ジャッジ時間 1,877 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
55,572 KB
testcase_01 AC 41 ms
55,916 KB
testcase_02 AC 38 ms
54,984 KB
testcase_03 AC 36 ms
55,176 KB
testcase_04 AC 37 ms
55,044 KB
testcase_05 AC 38 ms
56,204 KB
testcase_06 AC 38 ms
55,856 KB
testcase_07 AC 37 ms
55,544 KB
testcase_08 AC 37 ms
57,028 KB
testcase_09 AC 39 ms
56,044 KB
testcase_10 AC 37 ms
56,160 KB
testcase_11 AC 37 ms
56,532 KB
testcase_12 AC 38 ms
55,884 KB
testcase_13 AC 37 ms
55,672 KB
testcase_14 AC 36 ms
55,176 KB
testcase_15 AC 38 ms
55,304 KB
testcase_16 AC 40 ms
61,880 KB
testcase_17 AC 41 ms
61,968 KB
testcase_18 AC 39 ms
55,700 KB
testcase_19 AC 41 ms
60,880 KB
testcase_20 AC 42 ms
60,432 KB
testcase_21 AC 40 ms
61,328 KB
testcase_22 AC 41 ms
60,848 KB
testcase_23 AC 40 ms
61,684 KB
testcase_24 AC 43 ms
61,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import lru_cache


@lru_cache(maxsize=None)
def isPrime(n):
    if n == 0 or n == 1:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    for i in range(3, int(n ** 0.5) + 1, 2):
        if n % i == 0:
            return False
    return True


def find_prime(x):
    x += 1
    for _ in range(5 * 10 ** 6):
        if isPrime(x):
            return x
        x += 1
    return -1


X, Y = map(int, input().split())
if isPrime(X) and isPrime(Y):
    print("Second")
    exit()

if isPrime(X):
    X, Y = Y, X
if isPrime(Y):
    move = find_prime(Y) - Y - 1
    if move % 2 == 0:
        print("Second")
    else:
        print("First")
    exit()

dx = find_prime(X) - X - 1
dy = find_prime(Y) - Y - 1
if (dx + dy) % 2 == 0:
    print("Second")
else:
    print("First")
0