結果

問題 No.36 素数が嫌い!
ユーザー maspy
提出日時 2020-01-01 12:57:28
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
実行時間 -
コード長 796 bytes
コンパイル時間 84 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 44,712 KB
最終ジャッジ日時 2024-11-22 00:28:05
合計ジャッジ時間 18,072 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 4
other RE * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(read())

def make_prime(U):
    is_prime = np.zeros(U,np.bool)
    is_prime[2] = 1
    is_prime[3::2] = 1
    M = int(U**.5)+1
    for p in range(3,M,2):
        if is_prime[p]:
            is_prime[p*p::p+p] = 0
    return is_prime, is_prime.nonzero()[0]

U = 10 ** 7 + 10
is_prime, primes = make_prime(U)

def solve(N):
    if N == 1:
        return False
    sq = int(N ** .5) - 10
    while (sq + 1) ** 2 <= N:
        sq += 1
    if N == sq:
        return not is_prime[sq]
    if N < U:
        return not is_prime[N]
    return np.any(N % primes == 0)

# [solve(x) for x in [30,5,1,16777216]]

answer = 'YES' if solve(N) else 'NO'
print(answer)
0