zoukankan      html  css  js  c++  java
  • cf 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 m zeroes. 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! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
    题意:让你找N的阶乘的末尾有m个0的数有多少,并输出n.
    解法:因为末尾是0和5的个数有关系,n!=n*(n-1)(n-2)…….*1,里面有多少个5,那么结果的末尾就有多少个0

    #include<stdio.h>
    #include<string.h>
    int a[10000];
    int main()
    {
        int n;
        while(scanf("%d",&n)!=-1)
        {
            int i,j;
            for(i=1;n>0;i++)//1*2*3*.....*(n-1)*找能被5整除的数
            {
            int we=i;
            while(we%5==0)//找到了就零的个数--
                {
                   we /= 5;
                    n--;
                }
            }
            if(n<0)
            {
                printf("0
    ");
            }
            else
            {
                printf("5
    ");
                for(int j=i-1;j<=i+3;j++)
                {
                    if(j<i+3)
                    printf("%d ",j);
                    if(j==i+3)
                        printf("%d
    ",j);
                }
            }
        }
    }
    "No regrets."
  • 相关阅读:
    值传递
    抽象类
    面向对象三大特征(二)--继承
    单例设计模式
    神奇的main方法详解
    面向对象的三大特征 ---- 封装
    变量、方法以及静态和非静态
    面向对象编程-类和对象
    数组
    力扣题库刷题(随时记录)
  • 原文地址:https://www.cnblogs.com/zxy160/p/7215150.html
Copyright © 2011-2022 走看看