• cf 633B A trivial problem


    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 mzeroes. Then print these k integers in increasing order.

    Example
    Input
    1
    
    Output
    5
    5 6 7 8 9 
    Input
    5
    
    Output
    0
    Note

    The factorial of n is equal to the product of all integers from 1 to n inclusive, that is n! = 1·2·3·...·n.

    In the first sample, 5! = 1206! = 7207! = 50408! = 40320 and 9! = 362880.

    #include<queue>
    #include<stack>
    #include<vector>
    #include<math.h>
    #include<stdio.h>
    #include<numeric>//STL数值算法头文件
    #include<stdlib.h>
    #include<string.h>
    #include<iostream>
    #include<algorithm>
    #include<functional>//模板类头文件
    using namespace std;
    
    const int INF=0x3f3f3f3f;
    const int maxn=500100;
    
    int m,cnt;
    int num[maxn],a[maxn];
    int fun(int n)
    {
        int ans=0;
        while(n)
        {
            n/=5;
            ans+=n;
        }
        return ans;
    }
    
    int main()
    {
        for(int i=0; i<maxn; i++)
            a[i]=fun(i);
        while(~scanf("%d",&m))
        {
            cnt=0;
            int i;
            for(i=0; i<maxn; i++)
            {
                if(a[i]==m)
                {
                    num[cnt++]=i;
                }
            }
            printf("%d
    ",cnt);
            if(cnt)
            {
                for(i=0; i<cnt; i++)
                {
                    if(i) printf(" ");
                    printf("%d",num[i]);
                }
                printf("
    ");
            }
        }
        return 0;
    }
    
    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    const int MAXN = 1e9;
    
    int fun(int n)
    {
        int cnt = 0;
        while(n)
        {
            n/=5;
            cnt+=n;
        }
        return cnt;
    }
    int Two(int l, int r, int m)
    {
        int ans = 0;
        while(r >= l)
        {
            int mid = (l + r) >> 1;
            int res = fun(mid);
            if(res < m)
                l = mid + 1;
            else if(res >= m)
            {
                r = mid - 1;
                ans = mid;
            }
        }
        return ans;
    }
    int main()
    {
        int m;
        while(cin >> m)
        {
            int l = 1, r = MAXN;
            int L = Two(l, r, m), R = Two(l, r, m+1);
            if(L == 0 || fun(R-1) != m) cout << 0 << endl;
            else
            {
                cout << R - L << endl;
                for(int i = L; i <= R-1; i++)
                {
                    if(i > L) cout << " ";
                    cout << i;
                }
                cout << endl;
            }
        }
        return 0;
    }

  • 相关阅读:
    套路
    委托、事件 茴字有几种写法
    数学 矩阵
    webForm系列 前端框架快速引用
    图片引用
    【HTML】Advanced6:HTML5 Forms Pt. 1: Input Types
    【HTML】Advanced5:Accessible Forms
    【HTML】Advanced4:Accessible Links
    【HTML】Advanced3:Tables: Columns, Headers, and Footers
    【HTML】Advanced2:Conditional Comments
  • 原文地址:https://www.cnblogs.com/nyist-xsk/p/7264862.html
Copyright © 2020-2023  润新知