結果

問題 No.689 E869120 and Constructing Array 3
ユーザー maspymaspy
提出日時 2020-03-04 16:30:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 133 ms / 1,000 ms
コード長 1,135 bytes
コンパイル時間 106 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 29,816 KB
最終ジャッジ日時 2023-08-04 03:14:05
合計ジャッジ時間 3,892 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
29,696 KB
testcase_01 AC 131 ms
29,708 KB
testcase_02 AC 129 ms
29,708 KB
testcase_03 AC 131 ms
29,696 KB
testcase_04 AC 131 ms
29,692 KB
testcase_05 AC 127 ms
29,756 KB
testcase_06 AC 129 ms
29,680 KB
testcase_07 AC 129 ms
29,708 KB
testcase_08 AC 131 ms
29,704 KB
testcase_09 AC 126 ms
29,764 KB
testcase_10 AC 129 ms
29,680 KB
testcase_11 AC 128 ms
29,676 KB
testcase_12 AC 133 ms
29,652 KB
testcase_13 AC 127 ms
29,752 KB
testcase_14 AC 129 ms
29,676 KB
testcase_15 AC 130 ms
29,816 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())

if K == 0:
    print(1)
    print(1)
    exit()

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

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

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

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