题干:
Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with exactly m zeroes. Are you among those great programmers who can solve this problem?
Input
The only line of input contains an integer m (1 ≤ m ≤ 100 000) — the required number of trailing zeroes in factorial.
Output
First print k — the number of values of n such that the factorial of n ends with m zeroes. Then print these k integers in increasing order.
Examples
Input
1Output
5
5 6 7 8 9Input
5Output
0Note
The factorial of n is equal to the product of all integers from 1 to n inclusive, that is n! = 1·2·3·...·n.
In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
解题报告:
直接暴力。
AC代码1:(二分)(31ms)
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
const int N = 0, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int n;
int main()
{
  while (~scanf("%d", &n))
  {
    int l = 0;
    int r = 1e9;
    while (l < r)
    {
      int m = (l + r + 1) >> 1;
      int five = 0;
      int tmp = m;
      while (tmp) { tmp /= 5; five += tmp; }
      if (five > n)r = m - 1;
      else l = m;
    }
    int R = l;
    l = 0;
    r = 1e9;
    while (l < r)
    {
      int m = (l + r) >> 1;
      int five = 0;
      int tmp = m;
      while (tmp) { tmp /= 5; five += tmp; }
      if (five < n)l = m + 1;
      else r = m;
    }
    int L = l;
    printf("%d\n", R - L + 1);
    for (int i = L; i <= R; ++i)printf("%d ", i);
    puts("");
  }
  return 0;
}
/*
【题意】
给你一个数组n(1<=n<=1e5)
让你输出有多少数的阶乘后恰好有n个0,并依次输出。
【类型】
二分or暴力
【分析】
肯定满足,数字越大,其后的0的个数也就越多。
于是我们可以二分出最小的l,使得fac[l]>=n
同时我们二分出最大的r,使得fac[r]<=n
然后答案就是区间段[l,r]
而算fac[l]有多少个0,就是查看fac[l]中有多少个5
因为n不大,所以另外一种做法是暴力。
我们直接求出fac[i]的末尾有多少个0即可
【时间复杂度&&优化】
O(log(n)log(n)) or O(nlogn)
*/
AC代码2:(枚举暴力网络版)(93ms)
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
const int N = 0, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int n;
void solve()
{
  int l = -1;
  int r = -2;
  int zero = 0;
  for (int i = 0; ; ++i)
  {
    for (int x = i; x && x % 5 == 0; x /= 5)++zero;
    if (zero == n)
    {
      if (l == -1)l = i;
      r = i;
    }
    else if (zero > n)break;
  }
  printf("%d\n", r - l + 1);
  for (int i = l; i <= r; ++i)printf("%d ", i);
  puts("");
}
int main()
{
  while (~scanf("%d", &n))
  {
    solve();
  }
  return 0;
}
AC代码3:(枚举自己a)
using namespace std;
int main()
{
  long long tmp,n,m,sum=0;
  long long l = -1,r = -1;
  int flag = 0;
  cin>>m;
//  tmp = m;
  for(int i = 1; i<=1000000; i++) {
    tmp = i;
    sum = 0;
    while(tmp!=0) {
      sum +=tmp/5;
      tmp/=5;
    }
    if(sum == m && l == -1) l = i,r = i,flag = 1;
    if(sum == m && flag == 1) r= i;
    if(sum>m && l == -1) {
      printf("0\n");
      return 0 ;
    }
    
  }
  printf("%d\n",r-l+1);
  for(int i = l; i<=r; i++) {
    printf("%d ",i);
  }
  return 0 ;
}
总结:
1.一些小变量的使用要注意啊!别用错了。
2.注意二分的使用!这种题型也可以!
                










