CodeForces - 633B A Trivial Problem 数论-阶乘后缀0

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\n");
            printf("%d",i);
            for(j=i+1;j<=i+4;j++){
                printf(" %d",j);
            }
            break;
        }
        else if(c>n){
            printf("0\n");
            break;
        }
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/yzm10/p/8724453.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值