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;
}

原文地址:https://www.cnblogs.com/nyist-xsk/p/7264862.html