Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
21
Task/Semiprime/PHP/semiprime.php
Normal file
21
Task/Semiprime/PHP/semiprime.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
// Semiprime
|
||||
|
||||
function primeFactorsCount($n)
|
||||
{
|
||||
$n = abs($n);
|
||||
$count = 0; // Result
|
||||
if ($n >= 2)
|
||||
for ($factor = 2; $factor <= $n; $factor++)
|
||||
while ($n % $factor == 0) {
|
||||
$count++;
|
||||
$n /= $factor;
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
echo "Enter an integer: ",
|
||||
$n = (int)fgets(STDIN);
|
||||
echo (primeFactorsCount($n) == 2 ?
|
||||
"It is a semiprime.\n" : "It is not a semiprime.\n");
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue