結果

問題 No.36 素数が嫌い!
ユーザー GrayCoderGrayCoder
提出日時 2018-08-13 18:41:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 513 ms / 5,000 ms
コード長 1,512 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 12,040 KB
実行使用メモリ 55,976 KB
最終ジャッジ日時 2023-10-24 16:42:40
合計ジャッジ時間 7,326 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 161 ms
31,968 KB
testcase_01 AC 283 ms
46,144 KB
testcase_02 AC 30 ms
10,160 KB
testcase_03 AC 30 ms
10,160 KB
testcase_04 AC 30 ms
10,160 KB
testcase_05 AC 34 ms
10,400 KB
testcase_06 AC 32 ms
10,416 KB
testcase_07 AC 31 ms
10,424 KB
testcase_08 AC 30 ms
10,280 KB
testcase_09 AC 31 ms
10,392 KB
testcase_10 AC 31 ms
10,360 KB
testcase_11 AC 155 ms
25,644 KB
testcase_12 AC 444 ms
55,976 KB
testcase_13 AC 444 ms
55,920 KB
testcase_14 AC 207 ms
39,172 KB
testcase_15 AC 30 ms
10,256 KB
testcase_16 AC 31 ms
10,160 KB
testcase_17 AC 29 ms
10,160 KB
testcase_18 AC 31 ms
10,268 KB
testcase_19 AC 138 ms
28,664 KB
testcase_20 AC 365 ms
55,916 KB
testcase_21 AC 259 ms
45,580 KB
testcase_22 AC 275 ms
46,636 KB
testcase_23 AC 163 ms
32,412 KB
testcase_24 AC 277 ms
34,852 KB
testcase_25 AC 177 ms
34,408 KB
testcase_26 AC 513 ms
38,616 KB
testcase_27 AC 388 ms
49,620 KB
testcase_28 AC 495 ms
37,848 KB
testcase_29 AC 424 ms
54,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin, stdout

input = lambda: stdin.readline()
write = stdout.write

def primes235(limit):
    yield 2; yield 3; yield 5
    if limit < 7: return
    modPrms = [7,11,13,17,19,23,29,31]
    gaps = [4,2,4,2,4,6,2,6,4,2,4,2,4,6,2,6]
    ndxs = [0,0,0,0,1,1,2,2,2,2,3,3,4,4,4,4,5,5,5,5,5,5,6,6,7,7,7,7,7,7]
    lmtbf = (limit + 23) // 30 * 8 - 1
    lmtsqrt = (int(limit ** 0.5) - 7)
    lmtsqrt = lmtsqrt // 30 * 8 + ndxs[lmtsqrt % 30]
    buf = [True] * (lmtbf + 1)
    for i in range(lmtsqrt + 1):
        if buf[i]:
            ci = i & 7; p = 30 * (i >> 3) + modPrms[ci]
            s = p * p - 7; p8 = p << 3
            for j in range(8):
                c = s // 30 * 8 + ndxs[s % 30]
                buf[c::p8] = [False] * ((lmtbf - c) // p8 + 1)
                s += p * gaps[ci]; ci += 1
    for i in range(lmtbf - 6 + (ndxs[(limit - 7) % 30])):
        if buf[i]: yield (30 * (i >> 3) + modPrms[i & 7])

def is_prime(n):
    if n == 2:
        return True
    if n < 2 or not n & 1:
        return False

    for i in range(3, n, 2):
        if not n % i:
            return False
        if i * i >= n:
            break
    return True

def main():
    N = int(input())

    if N < 8:
        write('NO\n')
        return

    n = int(N ** 0.5)
    prime_list = []
    for i in primes235(n):
        prime_list.append(i)

    for i in prime_list:
        d, m = divmod(N, i)
        if not m and not is_prime(d):
            write('YES\n')
            return
    write('NO\n')

main()
0