Semiprime: Difference between revisions

(Added Arturo implementation)
Line 2,844:
1679 is ... a semiprime
1680 is ... NOT a semiprime
</pre>
 
== {{header|TypeScript}} ==
{{trans|ASIC}}
<lang javascript>
// Semiprime
 
function primeFactorsCount(n: number): number {
n = Math.abs(n);
var count = 0; // Result
if (n >= 2)
for (factor = 2; factor <= n; factor++)
while n % factor == 0) {
count++;
n /= factor;
}
return count;
}
 
const readline = require('readline').createInterface({
input: process.stdin, output: process.stdout
});
 
readline.question('Enter an integer: ', sn => {
var n = parseInt(sn);
console.log(primeFactorsCount(n) == 2 ?
"It is a semiprime." : "It is not a semiprime.");
readline.close();
});
</lang>
{{out}}
<pre>
Enter an integer: 33
It is a semiprime.
</pre>
<pre>
Enter an integer: 60
It is not a semiprime.
</pre>
 
Anonymous user