I got bored and created this script for the sole purpose of just practicing looping. I'm trying to use a factorial number for example 479001600
which is the factorial of 12! and I'm feeding it to the loop to find what number is 479001600
a factorial of. Using the technique 479001600/2 -> 239500800/3 -> 79833600/4 ...-> previous_int/n+1
I've come up with the following code which works only till 12! but fails on 13! onwards:
<?php
function inv($int){
$j=2;
for($i=0;$i<$j;$i++){
$prod = $int/$j;
if($prod !== 1){
$int = $prod;
echo $prod. "<br>";
$j++;
} elseif($prod == 1) {
return $j;
}
}
}
echo inv(6227020800); // 13!
?>
When I try to compute the 6227020800 to 13! I get the following output:
3113510400 1037836800 259459200 51891840 8648640 1235520 154440 17160 1716 156 13 1 0.071428571428571 0.0047619047619048 0.00029761904761905 1.750700280112E-5 9.7261126672891E-7 5.1190066669943E-8 2.5595033334971E-9 1.2188111111891E-10 ...etc
Несмотря на то, что он получает целое число 1 через деление цикла, он продолжает игнорировать оператор if. Я что-то делаю не так? Любая помощь будет оценена, также я хочу избежать использования функций gmp_.
$prod !== 1
(не совпадает) на$prod != 1
(не равно). - person   schedule 20.01.2014