結果

問題 No.689 E869120 and Constructing Array 3
ユーザー maspymaspy
提出日時 2020-03-04 16:20:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 991 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 44,220 KB
最終ジャッジ日時 2024-04-22 01:41:19
合計ジャッジ時間 10,919 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 536 ms
44,092 KB
testcase_01 AC 545 ms
43,960 KB
testcase_02 AC 544 ms
43,836 KB
testcase_03 AC 540 ms
43,956 KB
testcase_04 AC 544 ms
44,100 KB
testcase_05 AC 543 ms
43,936 KB
testcase_06 AC 544 ms
43,960 KB
testcase_07 AC 545 ms
43,836 KB
testcase_08 AC 540 ms
43,836 KB
testcase_09 AC 545 ms
44,220 KB
testcase_10 AC 540 ms
43,964 KB
testcase_11 AC 547 ms
44,220 KB
testcase_12 WA -
testcase_13 AC 536 ms
44,092 KB
testcase_14 AC 544 ms
44,096 KB
testcase_15 AC 542 ms
44,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


# %%
import numpy as np


# %%
def prime_table(N):
    """Create prime table of interval [0, N)

    Parameters
    ----------
    N : int
        Upper bound. N must be >= 2.

    Returns
    -------
    tuple of two arrays.
    is_prime: is_prime[i] = True iff i is prime.
    primes: primes[i] = (i+1)-th prime
    """
    is_prime = np.zeros(N, np.bool_)
    is_prime[2] = 1
    is_prime[3::2] = 1
    for p in range(3, N, 2):
        if p * p > N:
            break
        if is_prime[p]:
            is_prime[p * p::p + p] = 0
    primes = np.where(is_prime)[0]
    return is_prime, primes


# %%
K = int(readline())


# %%
is_prime, primes = prime_table(10 ** 4)

# %%
n = 0
while (n + 1) * (n + 2) // 2 <= K:
    n += 1

C = [1] * n + [2]
rest = K - n * (n + 1) // 2

# %%
C += (primes[10:][:rest] - 2).tolist()
print(len(C))
print(*C)
0