zoukankan      html  css  js  c++  java
  • Trailing Zeroes (III) 假设n!后面有x个0.现在要求的是,给定x,要求最小的n; 判断一个n!后面有多少个0,通过n/5+n/25+n/125+...

    /**
    题目:Trailing Zeroes (III) 
    链接:https://vjudge.net/contest/154246#problem/N
    题意:假设n!后面有x个0.现在要求的是,给定x,要求最小的n;
    思路:判断一个n!后面有多少个0,通过n/5+n/25+n/125+...
    */
    
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    typedef long long ll;
    const int maxn = 5*1e8+1;
    int num(int m)
    {
        int cnt = 0;
        while(m>0){
            cnt += m/5;
            m /= 5;
        }
        return cnt;
    }
    int main()
    {
        int T, cas=1, q;
        cin>>T;
        while(T--)
        {
            scanf("%d",&q);
            int lo = 5, hi = maxn;
            int m;
            int mis = maxn;
            while(lo<=hi){
                m = (lo+hi)/2;
                int t = num(m);
                if(t>=q){
                    if(t==q) mis = min(mis,m);
                    hi = m-1;
                }else
                {
                    lo = m+1;
                }
            }
            if(mis==maxn)
                printf("Case %d: impossible
    ",cas++);
            else
                printf("Case %d: %d
    ",cas++,mis);
    
        }
        return 0;
    }
  • 相关阅读:
    AWS 移动推送到iOS设备,Amazon Pinpoint
    iOS 上架注意
    iOS 开发笔记
    TestFlight 测试
    iOS UI基础-21 WKWebView
    Parallels Desktop 重装系统
    Xcode8.2 继续使用插件
    iOS JSPatch 热修复使用
    Mac 配置环境变量
    Mac 安装 JDK
  • 原文地址:https://www.cnblogs.com/xiaochaoqun/p/6651005.html
Copyright © 2011-2022 走看看