n的阶乘末尾有几个0?

unsigned int count(unsigned int n) {
  unsigned int cnt = 0;
  unsigned int i, j;
  for (i = 1; i <= n; i++) {
      j = i;
      while (j % 5 == 0) {
          cnt++;
          j /= 5;
      }
  }
  return cnt;
}

unsigned int count(unsigned int n) {
  unsigned int cnt = 0;
  while (n) {
      cnt += n / 5;
      n /= 5;
  }
  return cnt;
}

本质是求有几个5

原文地址:https://www.cnblogs.com/chenkkkabc/p/2942966.html