📜  PHP程序来计算一个数字的阶乘中的尾随零

📅  最后修改于: 2022-05-13 01:54:11.327000             🧑  作者: Mango

PHP程序来计算一个数字的阶乘中的尾随零

给定一个整数 n,编写一个函数,返回 n! 中尾随零的计数。

例子 :

Input: n = 5
Output: 1 
Factorial of 5 is 120 which has one trailing 0.

Input: n = 20
Output: 4
Factorial of 20 is 2432902008176640000 which has
4 trailing zeroes.

Input: n = 100
Output: 24
Trailing 0s in n! = Count of 5s in prime factors of n!
                  = floor(n/5) + floor(n/25) + floor(n/125) + ....
PHP
= 1; $i *= 5)
        $count += $n / $i;
  
    return $count;
}
  
// Driver Code
  
$n = 100;
echo "Count of trailing 0s in ", 100, 
     "! is ", findTrailingZeros($n);
  
// This code is contributed by vt_m
?>


输出:
Count of trailing 0s in 100! is 24

有关更多详细信息,请参阅有关在数字的阶乘中计数尾随零的完整文章!