結果

問題 No.689 E869120 and Constructing Array 3
コンテスト
ユーザー beet
提出日時 2018-05-18 23:06:08
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,005 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,095 ms
コンパイル使用メモリ 187,012 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2026-03-17 09:22:12
合計ジャッジ時間 2,267 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
using Int = long long;

Int isprime(Int x){
  if(x<=1) return 0;
  for(Int i=2;i*i<=x;i++)
    if(x%i==0) return 0;
  return 1;
}

//INSERT ABOVE HERE
signed main(){
  vector<Int> ps1,ps2;
  for(Int i=11;ps1.size()<250u;i+=6)
    if(isprime(i)) ps1.emplace_back(i);
  for(Int i=13;ps2.size()<250u;i+=6)
    if(isprime(i)) ps2.emplace_back(i);

  Int k;
  cin>>k;
  if(!k){
    cout<<1<<endl<<1<<endl;
    return 0;
  }

  for(Int i=0;i<250;i++){
    for(Int x=1;x<250;x++){
      for(Int y=0;y<250;y++){
	if(k<i*y+x*y+(x*(x-1)/2)) continue;
	if((k-(i*y+x*y+(x*(x-1)/2)))%x) continue;
	Int z=(k-(i*y+x*y+(x*(x-1)/2)))/x;
	//cout<<i<<" "<<x<<" "<<y<<" "<<z<<endl;
	Int n=i+x+y+z;
	if(n>250) continue;
	cout<<n<<endl;
	for(Int j=0;j<x;j++){
	  if(j) cout<<" ";
	  cout<<1;
	}
	for(Int j=0;j<i;j++)
	  cout<<" "<<ps2[j]-2;
	for(Int j=0;j<z;j++)
	  cout<<" "<<ps1[j]-1;
	for(Int j=0;j<y;j++)
	  cout<<" "<<2;
	cout<<endl;
	return 0;
      }
    }
  }
  return 0;
}
0