zoukankan      html  css  js  c++  java
  • 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");
    
    }
  • 相关阅读:
    无题
    晒新玩具
    PHP开发调试环境配置(基于wampserver+Eclipse for PHP Developers )
    Java
    [转]const 与 readonly知多少
    Watin 杂谈
    WCF
    [转]: 两分钟彻底让你明白Android Activity生命周期(图文)!
    【转】单链表逆序
    桥梁模式和适配器模式的区别
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5223561.html
Copyright © 2011-2022 走看看