zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    elasticsearch的安装
    default_scope and unscoped
    RSpec + Spork + Autotest 给Rails 3添加快速自动化测试
    ubuntu收过带个winmail.dat的邮件
    网站链接
    github
    js笔记
    mba首页js
    mba精锐视角js
    mongodb常用命令
  • 原文地址:https://www.cnblogs.com/yzm10/p/8724453.html
Copyright © 2011-2022 走看看