Posts

Showing posts from February, 2021

Geek For Geeks | Trailing Zeroes in a factorial of a number | Java

For an integer  N  find the number of trailing zeroes in  N!. Example 1: Input: N = 5 Output: 1 Explanation: 5! = 120 so the number of trailing zero is 1. Expected Time Complexity:  O(logN) Expected Auxiliary Space:  O(1) Constraints: 1 <= N <= 10 9   public class  TrailingZeroes { public static void main (String[] args) { int n = 384 ; int count = 0 ; for ( int i = 5 ; n/i >= 1 ; i *= 5 ) { count += n/i ; } System. out .println(count) ; } }