結果

問題 No.689 E869120 and Constructing Array 3
ユーザー mamekinmamekin
提出日時 2018-05-18 23:39:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 1,000 ms
コード長 1,382 bytes
コンパイル時間 1,129 ms
コンパイル使用メモリ 109,868 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 23:16:24
合計ジャッジ時間 2,694 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
4,376 KB
testcase_01 AC 8 ms
4,380 KB
testcase_02 AC 8 ms
4,376 KB
testcase_03 AC 8 ms
4,376 KB
testcase_04 AC 8 ms
4,376 KB
testcase_05 AC 8 ms
4,380 KB
testcase_06 AC 8 ms
4,376 KB
testcase_07 AC 8 ms
4,376 KB
testcase_08 AC 8 ms
4,380 KB
testcase_09 AC 8 ms
4,376 KB
testcase_10 AC 8 ms
4,376 KB
testcase_11 AC 7 ms
4,376 KB
testcase_12 AC 9 ms
4,376 KB
testcase_13 AC 8 ms
4,376 KB
testcase_14 AC 8 ms
4,376 KB
testcase_15 AC 8 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

void findPrime(int N, vector<bool>& isPrime)
{
    isPrime.assign(N+1, true);
    isPrime[0] = isPrime[1] = false;
    for(int i=2; i*i<=N; i++){
        if(isPrime[i]){
            for(int j=i; i*j<=N; j++){
                isPrime[i*j] = false;
            }
        }
    }
}

const int MAX = 1000000;

int main()
{
    vector<bool> isPrime;
    findPrime(2*MAX, isPrime);

    int k;
    cin >> k;

    int n = 2;
    while(n <= 100 && n * (n - 1) / 2 + n <= k)
        ++ n;
    -- n;

    vector<int> v(n, 1);
    v.push_back(2);
    k -= n * (n - 1) / 2 + n;
    while(k >= n){
        v.push_back(4);
        k -= n;
    }
    for(int i=3; k>0; ++i){
        if(isPrime[i+2] && !isPrime[i+4]){
            v.push_back(i);
            -- k;
        }
    }

    n = v.size();
    cout << n << endl;
    cout << v[0];
    for(int i=1; i<n; ++i)
        cout << ' ' << v[i];
    cout << endl;

    return 0;
}
0