zoukankan      html  css  js  c++  java
  • LightOJ 1138

    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 <map>
    #include <set>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <queue>
    #include <iostream>
    #include <stack>
    #include <cmath>
    #include <vector>
    #include <cstdlib>
    //#include <bits/stdc++.h>
    #define space " "
    using namespace std;
    typedef long long LL;
    //typedef __int64 Int;
    typedef pair<int,int> paii;
    const int INF = 0x3f3f3f3f;
    const double ESP = 1e-5;
    const double Pi = acos(-1);
    const int MOD = 1e9+5;
    const int MAXN = 1e5;
    bool flag ;
    bool judge(int x, int y) {
        int f = 5;
        int sum = 0;
        while (f <= x) {
            sum = sum + x/f;
            f = f*5;
        }
        if (sum == y) flag = true;
        return sum >= y;
    }
    int main() {
        int t, n;
        int cnt = 0;
        scanf("%d", &t);
        while (t--) {
            scanf("%d", &n);
            int ans; flag = false;
            int lb = 0, ub = 1e9;
            while (ub >= lb) {
                int mid = (ub + lb) >> 1;
                if (judge(mid, n)) {
                    ans = mid; ub = mid - 1;
                }
                else lb = mid + 1;
            }
            if (flag) printf("Case %d: %d
    ", ++cnt, ans);
            else printf("Case %d: impossible
    ", ++cnt);
        }
        return 0;
    }
    
    


  • 相关阅读:
    线性表17 数据结构和算法22
    线性表16:双向链表 数据结构和算法21
    栈和队列 数据结构和算法23
    栈和队列
    栈和队列
    栈和队列
    线性表16:双向链表 数据结构和算法21
    线性表17 数据结构和算法22
    桌面IE图标无法删除及IE劫持到g1476.cn的彻底恢复
    个人所得税率
  • 原文地址:https://www.cnblogs.com/cniwoq/p/6770804.html
Copyright © 2011-2022 走看看