codeforces 633B A Trivial Problem

B. A Trivial Problem
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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
1
output
5
5 6 7 8 9
input
5
output
0
Note

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.

题意:给一个数m表示一个数的阶乘的值后边0的个数,问这样的数有几个并写出来

题解:判断5的个数详解见http://www.cnblogs.com/tonghao/p/4823114.html

因为用二分时区间开的太小没发现 错了几个小时

#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define PI atan(1.0)*4
#define DD double
#define MAX 100100
#define mod 100
#define dian 1.000000011
#define INF 0x3f3f3f
using namespace std;
int fun(int x)
{
	int cnt=0;
	while(x)
	{
		cnt+=x/5;
		x/=5;
	}
	return cnt;
}
int fen(int m)
{
	 int left=0;
	 int right=1001000000;
	 int mid,ans;
	 ans=0;
	 while(left<=right)
	 {
	 	 mid=(left+right)/2;
	 	 if(fun(mid)>=m)
	 	 {
	 	 	right=mid-1;
	 	 	//ans=mid;
	 	 }
	 	 	  
	 	 else
	 	 	left=mid+1;
	 }
	 return left;
}
int s[MAX];
int main()
{
    int n,m,j,i,t,k;
	while(scanf("%d",&n)!=EOF)
	{
		int sum=0;k=0;
	    int L,R;
	    L=fen(n);R=fen(n+1);
//	    if(L==0||fun(R-1)!=n)
//	    {
//	    	printf("0\n");
//	    	continue;
//	    }
	    for(i=L;i<R;i++)
	    {
	    	if(fun(i)==n)
	    	{
	    		sum++;
	    		s[k++]=i;
	    	}
	    }
		printf("%d\n",sum);
		if(sum!=0)
		{
			for(i=0;i<k-1;i++)
		        printf("%d ",s[i]);
		    printf("%d\n",s[k-1]);
		}
		
	} 
	return 0;
}

  

posted @ 2016-03-03 20:57  非我非非我  阅读(414)  评论(0编辑  收藏  举报