zoukankan      html  css  js  c++  java
  • LightOJ 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

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define mod 1000000007
    #define pi (4*atan(1.0))
    const int N=1e5+10,M=4e6+10,inf=1e9+10;
    int a[20]={5,25,125,625,3125,15625,78125,390625,1953125,9765625,48828125,244140625,1220703125};
    int check(int x)
    {
        int sum=0;
        for(int i=0;i<13;i++)
            sum+=x/a[i];
        return sum;
    }
    int main()
    {
        int x,y,z,i,t;
        int T,cas=1;
        scanf("%d",&T);
        while(T--)
        {
            scanf("%d",&x);
            int st=0;
            int en=500000000;
            while(st<en)
            {
                int mid=(st+en)>>1;
                if(check(mid)>=x)
                en=mid;
                else
                st=mid+1;
            }
            printf("Case %d: ",cas++);
            if(check(st)==x)
            printf("%d
    ",st);
            else
            printf("impossible
    ");
        }
        return 0;
    }
  • 相关阅读:
    redis-client和redis-template存储的key的格式不一样
    dubbo+zookeeper基础
    java面试题1
    Spring线程池(异步、同步)
    Java并发多线程
    Java并发-并发工具类JUC
    Java并发面试题
    ActiveMQ
    一键部署springboot到Docker
    Quartz任务调度学习
  • 原文地址:https://www.cnblogs.com/jhz033/p/5814461.html
Copyright © 2011-2022 走看看