Why can't I just divide by all powers of 5?


#1

int Solution::trailingZeroes(int A) {
int five = 0, two = 0;
five += A/5;
five += A/25;
five += A/625;
five += (int)(A/3125);

return five;

}

It doesn’t calculate the right answer, but why?


#2

you missed 125, just try adding it.


#3

whats wrong with this code

int Solution::trailingZeroes(int A) {

int c = (A/5) + (A/25) + (A/125) + (A/625) + (A/3125) + (A/15625) +(A/78125) +(A/390625);
return c;

}


#4

keep doing it until A/5^i for some integer i becomes zero, as the test cases aren’t in constraint 1 <= A <= 10000.