Trailing number of 0 s in product of two factorials | Java program for count number of trailing zeros in N ! * M ! ; Returns number of zeros in factorial n ; dividing x by powers of 5 and update count ; Returns count of trailing zeros in M ! x N ! ; Driver program
import java . io . * ; class GFG { static int trailingZero ( int x ) { int i = 5 , count = 0 ; while ( x > i ) { count = count + x / i ; i = i * 5 ; } return count ; } static int countProductTrailing ( int M , int N ) { return trailingZero ( N ) + trailingZero ( M ) ; } public static void main ( String args [ ] ) { int N = 67 , M = 98 ; System . out . println ( countProductTrailing ( N , M ) ) ; } }