結果

問題 No.726 Tree Game
ユーザー nadare
提出日時 2018-08-24 21:56:10
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 782 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-06-23 07:14:46
合計ジャッジ時間 1,986 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
from bisect import bisect, bisect_left
from math import sqrt

def primes(N):
    sieve = [True]*(N+1)
    sieve[:2] = [False, False]
    P = []
    
    for i in range(2, N):
        if sieve[i]:
            P.append(i)
            for j in range(2*i, N, i):
                sieve[j] = False
    return P

def isprime(X, P):
    if X <= P[-1]:
        return X == P[bisect_left(P, X)]
    for p in P[:bisect(P, sqrt(X)+1)]:
        if X%p == 0:
            return False
    else:
        return True

P = primes(int(sqrt(2*10**9)))
X, Y = map(int, input().split())

secwin = True

while not isprime(X, P):
    X += 1
    secwin = not secwin

while not isprime(Y, P):
    Y += 1
    secwin = not secwin

if secwin:
    print("Second")
else:
    print("First")
0