結果
| 問題 |
No.726 Tree Game
|
| コンテスト | |
| ユーザー |
maspy
|
| 提出日時 | 2020-02-04 13:30:26 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 35 ms / 2,000 ms |
| コード長 | 1,056 bytes |
| コンパイル時間 | 89 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 11,264 KB |
| 最終ジャッジ日時 | 2024-09-21 07:19:30 |
| 合計ジャッジ時間 | 1,851 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 25 |
ソースコード
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')
maspy