CodeForces 633B A Trivial Problem(找规律)

    xiaoxiao2021-03-25  79

    题目:

    B. A Trivial Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

    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.

    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! = 1206! = 7207! = 50408! = 40320 and 9! = 362880.

    思路:

    这个题是求阶乘尾数的0的个数,2*5等于10,这样就出现了0,所以我们找5的个数就行了

    代码:

    #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <string> #include <iostream> #include <stack> #include <map> #include <queue> #include <vector> #include <algorithm> #define mem(a,b) memset(a,b,sizeof(a)) #define N 999999+20 #define M 200010 #define MOD 1000000000+7 #define inf 0x3f3f3f3f using namespace std; int main() { int num=0,b=5,c,n; scanf("%d",&n); while(num<=n) { c=b; while(c%5==0) { num++; c/=5; } if(num==n) { printf("5\n"); for(int i=0; i<5; i++) printf("%d ",b+i); return 0; } b+=5; } printf("0\n"); }

    转载请注明原文地址: https://ju.6miu.com/read-32714.html

    最新回复(0)