結果

問題 No.843 Triple Primes
ユーザー watarimaycry2watarimaycry2
提出日時 2020-10-24 17:46:58
言語 JavaScript
(node v21.7.1)
結果
WA  
実行時間 -
コード長 3,029 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 6,944 KB
実行使用メモリ 53,752 KB
最終ジャッジ日時 2024-07-21 15:20:58
合計ジャッジ時間 7,985 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
40,192 KB
testcase_01 AC 218 ms
52,476 KB
testcase_02 AC 85 ms
42,452 KB
testcase_03 AC 81 ms
42,452 KB
testcase_04 AC 82 ms
40,448 KB
testcase_05 AC 79 ms
40,320 KB
testcase_06 AC 82 ms
42,444 KB
testcase_07 AC 174 ms
52,344 KB
testcase_08 AC 185 ms
52,220 KB
testcase_09 AC 197 ms
50,436 KB
testcase_10 AC 182 ms
52,216 KB
testcase_11 AC 191 ms
50,176 KB
testcase_12 AC 201 ms
52,212 KB
testcase_13 AC 199 ms
52,472 KB
testcase_14 AC 198 ms
52,216 KB
testcase_15 AC 178 ms
50,436 KB
testcase_16 AC 177 ms
50,176 KB
testcase_17 WA -
testcase_18 AC 78 ms
42,324 KB
testcase_19 AC 80 ms
42,228 KB
testcase_20 AC 114 ms
46,188 KB
testcase_21 AC 100 ms
45,440 KB
testcase_22 AC 146 ms
48,128 KB
testcase_23 AC 149 ms
50,120 KB
testcase_24 AC 118 ms
48,220 KB
testcase_25 AC 110 ms
46,064 KB
testcase_26 AC 196 ms
50,440 KB
testcase_27 AC 95 ms
46,932 KB
testcase_28 AC 204 ms
50,184 KB
testcase_29 AC 122 ms
48,108 KB
testcase_30 AC 194 ms
52,220 KB
testcase_31 AC 97 ms
45,184 KB
testcase_32 AC 91 ms
44,800 KB
testcase_33 AC 127 ms
50,512 KB
testcase_34 AC 143 ms
50,252 KB
testcase_35 AC 189 ms
50,436 KB
testcase_36 AC 108 ms
45,936 KB
testcase_37 AC 175 ms
51,588 KB
testcase_38 AC 161 ms
53,752 KB
testcase_39 AC 194 ms
52,220 KB
testcase_40 AC 77 ms
40,192 KB
testcase_41 WA -
testcase_42 AC 169 ms
50,308 KB
testcase_43 AC 186 ms
52,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
	};
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var N = nextInt();
	var map = sieveOfEratos(N);
	myerr(map.size);
	var output = 0;
	var list = Array.from(map);
	for(var i = 0; i < list.length; i++){
		if(map.has(Math.sqrt(list[i] + 2))){
			output++;
		}
	}
	myout(output * 2 - 1);
}
function sieveOfEratos(val){
  var primes = new Set();
  var nums = new Set();
  var used = [2,3,5,7,11];//これらは既に素数であるとする
  var underPrime = 13;//この値から+2ごとに追加。↑の値で割り切れたものは何もしない
  if(val <= 1){
     return nums;
  }
  for(var i = 0; i < used.length; i++){if(used[i] <= val){nums.add(used[i]);}}
  for(var i = underPrime; i <= val; i = i + 2){
    var continued = false;
    for(var j = 0; j < used.length; j++){
      if(i % used[j] == 0){continued = true; break;}
    }
    if(continued){continue;}
    nums.add(i);
  }
  for(var i = 2; i <= Math.sqrt(val); (i == 2) ? i++ : i = i + 2){
    if(!nums.has(i)){continue;}
    var count = 1;
    while(i * count <= val){
      if(i <= 11 && used.indexOf(i) != -1){break;}
      if(count == 1){primes.add(i);}
      nums.delete(i * count);
      count++;
    }
  }
  var primeItr = Array.from(primes);
  for(var i = 0; i < primeItr.length; i++){
    nums.add(primeItr[i]);
  }
  return nums;
}
0