zoukankan      html  css  js  c++  java
  • lightoj 1138

    题目链接:http://lightoj.com/volume_showproblem.php?

    problem=1138

    题意:问 N。 末尾 0 的个数为 Q 个的数是什么?

    解法:二分枚举N,由于0是由5×2 出现的,2的个数比5多故计算5的个数就可以。

    代码:

    #include <stdio.h>
    #include <ctime>
    #include <math.h>
    #include <limits.h>
    #include <complex>
    #include <string>
    #include <functional>
    #include <iterator>
    #include <algorithm>
    #include <vector>
    #include <stack>
    #include <queue>
    #include <set>
    #include <map>
    #include <list>
    #include <bitset>
    #include <sstream>
    #include <iomanip>
    #include <fstream>
    #include <iostream>
    #include <ctime>
    #include <cmath>
    #include <cstring>
    #include <cstdio>
    #include <time.h>
    #include <ctype.h>
    #include <string.h>
    #include <assert.h>
    
    using namespace std;
    
    long long count_num(long long n)
    {
        long long num = 0;
        while (n)
        {
            num += n / 5;
            n /= 5;
        }
        return num;
    }
    
    int main()
    {
        int t;
        scanf("%d",&t);
        int cases = 1;
        while (t--)
        {
            int n;
            scanf("%d",&n);
            printf("Case %d: ",cases++);
    
            long long left = 1;
            long long right = 1000000000000;
            long long mid;
    
            while (left <= right)
            {
                mid = (right + left) / 2;
                long long tmp = count_num(mid);
                if (tmp >= n)
                    right = mid - 1;
                else
                    left = mid + 1;
            }
            if (count_num(left) != n)
                puts("impossible");
            else
                printf("%lld
    ",left);
        }
        return 0;
    }
  • 相关阅读:
    设计模式(十):Decorator装饰者模式 -- 结构型模式
    设计模式(九):Composite组合模式 -- 结构型模式
    Anagrams
    Gas Station
    Unique Binary Search Trees II
    Trapping Rain Water
    4Sum
    3Sum Closest
    3Sum
    Longest Valid Parentheses
  • 原文地址:https://www.cnblogs.com/yfceshi/p/7148962.html
Copyright © 2011-2022 走看看