zoukankan      html  css  js  c++  java
  • light oj 1138

    1138 - Trailing Zeroes (III)
    Time Limit: 2 second(s) Memory Limit: 32 MB

    You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the trail in decimal notation. As you know N! = 1*2*...*N. For example, 5! = 120, 120 contains one zero on the trail.

    Input

    Input starts with an integer T (≤ 10000), denoting the number of test cases.

    Each case contains an integer Q (1 ≤ Q ≤ 108) in a line.

    Output

    For each case, print the case number and N. If no solution is found then print 'impossible'.

    Sample Input

    Output for Sample Input

    3

    1

    2

    5

    Case 1: 5

    Case 2: 10

    Case 3: impossible

    以前在杭电上做过跟这个类似的题,主要考察的知识点一样,只是那个是给出n求0的个数,这个给出0的个数求n

    题解:主要还是求数中含有5的个数

    #include<stdio.h>
    #include<string.h>
    #define LL long long
    LL fun(LL x)
    {
    	LL ans=0;
    	while(x)
    	{
    		ans+=x/5;
    		x/=5;
    	}
    	return ans;
    }
    int main()
    {
    	int t,k=1;
    	LL n;
    	scanf("%d",&t);
    	while(t--)
    	{
    		scanf("%lld",&n);
    		LL l=0,r=500000000,mid,ans;
    		while(r>l)
    		{
    			mid=(l+r)/2;
    			if(fun(mid)>=n)
    			{
    				ans=mid;
    				r=mid;
    			}	
    			else
    			    l=mid+1;
    		} 
    		printf("Case %d: ",k++);
    		if(fun(ans)!=n)                           
    		printf("impossible
    ");
    		else
    		printf("%lld
    ",ans);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    常见的灰度发布系统规则
    golang中的路由分组
    艾森豪威尔矩阵
    列文定理
    吃狗粮定理
    mysql事务 锁
    mysql中explain优化分析
    mysql hash索引优化
    各种浏览器内核介绍
    浏览器 兼容性问题总结
  • 原文地址:https://www.cnblogs.com/tonghao/p/4962105.html
Copyright © 2011-2022 走看看