結果

問題 No.726 Tree Game
ユーザー 👑 rin204
提出日時 2022-10-30 17:03:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 940 bytes
コンパイル時間 196 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 52,352 KB
最終ジャッジ日時 2024-07-07 08:26:23
合計ジャッジ時間 1,877 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

def isprime(n):
    if n <= 1:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False
    
    A = [2, 325, 9375, 28178, 450775, 9780504, 1795265022]
    s = 0
    d = n - 1
    while d % 2 == 0:
        s += 1
        d >>= 1
    
    for a in A:
        if a % n == 0:
            return True
        x = pow(a, d, n)
        if x != 1:
            for t in range(s):
                if x == n - 1:
                    break
                x = x * x % n
            else:
                return False
    return True
        


y, x = map(int, input().split())
if x > y:
    x, y = y, x

if isprime(y) and isprime(x):
    print("Second")
elif x == 2 or y == 2:
    print("Second")
elif x == 1 and y == 1:
    print("Second")
elif (y + x) & 1:
    if x == 1:
        print("Second")
    else:
        print("First")
else:
    if x == 1:
        print("First")
    else:
        print("Second")
0