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

    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

    水题一发,直接二分查找。

    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #define LL long long
    using namespace std;
    LL n;
    LL erfen()
    {
        LL ans=-1, l=5, r=400000020;//想想r的值为什么这样定(因为此时r!等于10^8+1)
        while(l<=r)
        {
            LL mid=(l+r)/2;
            LL sum=0, s=mid;
            while(s>0)
                sum+=s/5,s/=5;
            if(sum==n)
            {
                r=mid-1;
                ans=mid;
            }
            else if(sum>n)
                r=mid-1;
            else
                l=mid+1;
        }
        return ans;
    }
    int main()
    {
        int T, t=1;
        scanf("%d", &T);
        while(T--)
        {
            scanf("%lld", &n);
            LL s=erfen();
            if(s!=-1)
            printf("Case %d: %lld
    ", t++, s);
            else
                printf("Case %d: impossible
    ", t++);
        }
    }
  • 相关阅读:
    DFS总结
    cmake-make-gcc(g++)
    std::function
    basic_string定义的相关string函数
    欧拉路径和欧拉回路
    正则表达式
    C++ Data Types
    关于uniapp的插槽
    关于微信H5 分享配置
    h5请求的时候总是会跨域
  • 原文地址:https://www.cnblogs.com/zhulei2/p/8206494.html
Copyright © 2011-2022 走看看