CodeForces

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.

Examples

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! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.

题目给出后缀0个数,输出n!满足条件的所有n值。

数论题。由于因子里含有偶数,所以非零末尾一定是偶数。产生0的因数一定包含5,所以题目就转化为寻找阶乘因子中含有5的个数。

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<set>
#include<algorithm>
#define MAX 1005
#define INF 0x3f3f3f3f
using namespace std;

int a[MAX];

int main()
{
    int n,c,i,j;
    scanf("%d",&n);
    c=0;
    for(i=1;i<=1000000;i++){  //注意这里是枚举阶乘的因子,需要大于后缀0最长的情况
        int ii=i;
        while(ii%5==0&&ii>0){
            c++;
            ii/=5;
        }
        if(c==n){
            printf("5
");
            printf("%d",i);
            for(j=i+1;j<=i+4;j++){
                printf(" %d",j);
            }
            break;
        }
        else if(c>n){
            printf("0
");
            break;
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/yzm10/p/8724453.html