how many "0"

how can i find how many digits "0" end record number N!(factorial N) in K-ary number system.
for example if N=10000 and K=10 answer is 2499, if N=123456789 and K=4800 answer is 15432096.
Last edited on
Calculate the number, then go trough it and count the 0s:
1
2
3
4
5
6
7
8
9
10
int n;
int zeros = 0;
///calculate n
do
{
    int digit = n%10; //returns the last digit. For example, 15%10 = 5
    if(digit == 0) {zeros++;} //if the last digit is 0, add one to the zero count
    n=n/10; //divide n by 10 to get rid of the last digit; 123/10=12

}while(n>0); //keep doing it untill the number is 0 
what about factorial n?
and system?
how many digits "0" end

"end"?

Does that mean "trailing zeroes" or "zeros at the end of" rather than "all digits in the factorial that happen to be 0?

Search web with "zeros in factorial". The solutions that you should find are for base 10. Adjust to base K.
Topic archived. No new replies allowed.