結果

問題 No.726 Tree Game
ユーザー H20
提出日時 2021-11-25 13:15:20
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 997 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 82,220 KB
実行使用メモリ 53,948 KB
最終ジャッジ日時 2024-06-28 04:01:48
合計ジャッジ時間 2,059 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

# python
# 補助関数
def suspect(a, t, n):
    x = pow(a, t, n)
    n1 = n - 1
    while t != n1 and x != 1 and x != n1:
        x = pow(x, 2, n)
        t <<= 1
    return t & 1 or x == n1

# メイン
# 2^64までの決定的アルゴリズムとして実装しているので、ランダム要素は無い
# ランダムとして用いる場合は、check_listにランダム抽出された数を採用し、20~50個程度試す
def miller_rabin(n):
    if n == 2:
        return True
    if n < 2 or n % 2 == 0:
        return False
    d = (n - 1) >> 1
    while d & 1 == 0:
        d >>= 1
    check_list = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41)
    for i in check_list:
        if i >= n:
            break
        if not suspect(i, d, n):
            return False
    return True

Y,X = map(int,input().split())
y = Y
x = X
while not miller_rabin(y+1):
    y+=1
while not miller_rabin(x+1):
    x+=1
temp = y-Y+x-X
if temp%2==0:
    print('Second')
else:
    print('First')
0