• 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
    ");
    //	    	continue;
    //	    }
    	    for(i=L;i<R;i++)
    	    {
    	    	if(fun(i)==n)
    	    	{
    	    		sum++;
    	    		s[k++]=i;
    	    	}
    	    }
    		printf("%d
    ",sum);
    		if(sum!=0)
    		{
    			for(i=0;i<k-1;i++)
    		        printf("%d ",s[i]);
    		    printf("%d
    ",s[k-1]);
    		}
    		
    	} 
    	return 0;
    }
    

      

  • 相关阅读:
    io系列浅谈
    git 删除分支--本地分支和远程分支
    提问须知
    PDF 补丁丁 0.6.2.3691 测试版发布
    PDF 补丁丁 0.6.2.3689 测试版发布
    .Net调用接口处理时间过长,前端访问超时解决方案
    Abp用多个DbContext
    IDEA 报错 Could not autowire. No beans of 'UserMapper' type found(无法自动装配。找不到类型为 'UserMapper' 的 bean)解决IDEA中自动装配,找不到类型的bean问题
    springboot整合springmvc拦截器
    springboot自动配置原理
  • 原文地址:https://www.cnblogs.com/tonghao/p/5240055.html
Copyright © 2020-2023  润新知