const n = parseInt(prompt('n'), 10);
const max = Math.floor(Math.sqrt(n));
const p = [];
for(let i=2; i<=n; i++) p[i] = true;
let x = 2;
while(x<=max) {
for(let i=2*x; i<=n; i+=x) p[i] = false;
while(!p[++x]) ;
}
for(let i=2; i<=n-2; i++) {
if(p[i] && p[i+2]) {
console.log(`${i}, ${i+2}`);
}
}
JS-エラトステネスのふるいで双子素数を求める
-----------------------
A [Pen](https://codepen.io/taquaki/pen/NwXgog) by [Takaaki Sato](https://codepen.io/taquaki) on [CodePen](https://codepen.io).
[License](https://codepen.io/taquaki/pen/NwXgog/license).