2以上の任意の自然数Pが素数か否かを判定するコードです。このコードはJavaScriptで書かれています。
const P = ; if ((P % 2) === 0) { if (P === 2) { console.log('P is a Prime number.') } else { console.log('P is not a Prime number.') } } else { for (var k = 1; ((2 * k) + 1) <= (P / 2); k = (k + 1)) { var c = ((2 * k) + 1) if (c === 3) { if ((P % c) === 0) { if (P === 3) { console.log('P is a Prime number.') break } else { console.log('P is not a Prime number.') break } } else { continue } } else { for (var l = 1; ((2 * l) + 1) <= (c / 2); l = (l + 1)) { var d = ((2 * l) + 1) if ((c % d) === 0) { break } else { continue } if (d >= ((c / 2) - (3 / 2))) { if ((P % c) === 0) { console.log('P is not a Prime number.') break break } else { continue } } else { continue } } if (c >= ((P / 2) - (3 / 2))) { console.log('P is a Prime number.') break } else { continue } } } };