結果

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

ソースコード

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)))
A, B = map(int, input().split())

if not (isprime(A+1, P) or isprime(B, P)):
    X, Y = A+1, B
    secwin1 = False
    i = 0
    while (not isprime(X, P)):
        i += 1
        X += 1
        secwin1 = not secwin1
    
    i = 0
    while (not isprime(Y, P)):
        i += 1
        Y += 1
        secwin1 = not secwin1
else:
    secwin1 = True

if not (isprime(A, P) or isprime(B+1, P)):
    X, Y = A, B+1
    secwin2 = False
    i = 0
    while (not isprime(X, P)):
        i += 1
        X += 1
        secwin2 = not secwin2
    
    i = 0
    while (not isprime(Y, P)):
        i += 1
        Y += 1
        secwin2 = not secwin2
else:
    secwin2 = True

if secwin1 & secwin2:
    print("Second")
else:
    print("First")
0