• Manthan, Codefest 16 B. A Trivial Problem 二分 数学


    B. A Trivial Problem

    题目连接:

    http://www.codeforces.com/contest/633/problem/B

    Description

    Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with exactly m zeroes. Are you among those great programmers who can solve this problem?

    Input

    The only line of input contains an integer m (1 ≤ m ≤ 100 000) — the required number of trailing zeroes in factorial.

    Output

    First print k — the number of values of n such that the factorial of n ends with m zeroes. Then print these k integers in increasing order.

    Sample Input

    1

    Sample Output

    5
    5 6 7 8 9

    Hint

    题意

    让你输出哪些数的阶乘后面恰好有k个0

    题解:

    首先阶乘后面的0的个数,就是2的因子数和5的因子数的最小值

    显然2的因子数肯定比5多,所以不用考虑2,直接考虑5就好了

    我是二分找的,当然在这个复杂度下面,直接暴力就好了

    代码

    #include<bits/stdc++.h>
    using namespace std;
    long long m;
    long long check(long long n)
    {
        long long num = 0;
        while(n)
        {
            num+=n/5;
            n=n/5;
        }
        return num;
    }
    int get(long long k)
    {
        long long l = 0,r = 1e15,ans = r;
        while(l<=r)
        {
            long long mid = (l+r)/2;
            if(check(mid)>=k)r=mid-1,ans=mid;
            else l=mid+1;
        }
        return ans;
    }
    int main()
    {
        scanf("%lld",&m);
        long long ans = get(m),ans2 = get(m+1);
        if(check(ans)==m&&check(ans2-1)==m)
        {
            cout<<ans2-ans<<endl;
            for(int i=ans;i<ans2;i++)
                cout<<i<<" ";
            cout<<endl;
        }
        else
            return puts("0");
    
    }
  • 相关阅读:
    Ajax基本用法
    浏览器兼容性问题
    对闭包的简单理解
    JSON
    Ajax知识
    对jsonp原理理解
    java Active Object模式(上)
    物联网传输协议MQTT
    谈谈如何在面试中发掘程序猿的核心竞争力
    响应式Web设计的9项基本原则
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5223561.html
Copyright © 2020-2023  润新知