結果

問題 No.726 Tree Game
ユーザー maspymaspy
提出日時 2020-02-04 13:30:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 1,056 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 11,944 KB
実行使用メモリ 10,560 KB
最終ジャッジ日時 2023-10-21 06:09:54
合計ジャッジ時間 1,969 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
10,496 KB
testcase_01 AC 36 ms
10,496 KB
testcase_02 AC 37 ms
10,496 KB
testcase_03 AC 33 ms
10,496 KB
testcase_04 AC 33 ms
10,496 KB
testcase_05 AC 33 ms
10,496 KB
testcase_06 AC 33 ms
10,496 KB
testcase_07 AC 33 ms
10,496 KB
testcase_08 AC 33 ms
10,496 KB
testcase_09 AC 34 ms
10,496 KB
testcase_10 AC 35 ms
10,496 KB
testcase_11 AC 33 ms
10,496 KB
testcase_12 AC 33 ms
10,560 KB
testcase_13 AC 33 ms
10,496 KB
testcase_14 AC 33 ms
10,496 KB
testcase_15 AC 33 ms
10,496 KB
testcase_16 AC 34 ms
10,496 KB
testcase_17 AC 33 ms
10,496 KB
testcase_18 AC 33 ms
10,496 KB
testcase_19 AC 33 ms
10,496 KB
testcase_20 AC 35 ms
10,496 KB
testcase_21 AC 34 ms
10,496 KB
testcase_22 AC 33 ms
10,496 KB
testcase_23 AC 34 ms
10,496 KB
testcase_24 AC 33 ms
10,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

X,Y = map(int,read().split())

def MillerRabinTest(n, maxiter = 10):
    import random
    if n == 1:
        return False
    elif n == 2:
        return True
    if not n&1:
        return False
    
    d = n - 1
    while not (d & 1):
        d >>= 1
        
    for _ in range(maxiter):
        a = random.randint(1,n-1)
        t = d
        x = pow(a,t,n)
        while (t != n-1) and (x != 1) and (x != n - 1):
            x = x * x % n
            t <<= 1
        if (x != n-1) and not (t & 1):
            return False
    return True

def next_prime(n):
    while True:
        n += 1
        if MillerRabinTest(n):
            return n

is_prime = [MillerRabinTest(x) for x in [X,Y]]

if is_prime[0] and is_prime[1]:
    print('Second')
elif X == 2 or Y == 2:
    print('Second')
else:
    dx = next_prime(X) - X - 1
    dy = next_prime(Y) - Y - 1
    if (dx + dy) & 1:
        print('First')
    else:
        print('Second')
0