You are viewing a single comment's thread. Return to all comments →
Code in JavaScript, works for all test cases:
function processData(input) { //Enter your code here let lines = input.split("\n").slice(1); lines.forEach(line => { let n = parseInt(line);
if (n < 2) { console.log("Not prime"); return; } let isPrime = true; if (n % 2 === 0 && n !== 2) { isPrime = false; } let sqrtN = Math.floor(Math.sqrt(n)); for (let i = 3; i <= sqrtN; i += 2) { // Skip even numbers if (n % i === 0) { isPrime = false; break; } } console.log(isPrime ? "Prime" : "Not prime"); });
}
Seems like cookies are disabled on this browser, please enable them to open this website
Day 25: Running Time and Complexity
You are viewing a single comment's thread. Return to all comments →
Code in JavaScript, works for all test cases:
function processData(input) { //Enter your code here let lines = input.split("\n").slice(1); lines.forEach(line => { let n = parseInt(line);
}