Codeforces 633B A Trivial Problem 【数论】

来源:互联网 发布:node 进入指定目录 编辑:程序博客网 时间:2024/05/04 06:51

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
55 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.


题意:问你那些数的阶乘末尾有连续m个0。


lightoj上基本原题:链接


思路:二分一下m和m+1就可以了。


AC代码:

#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;typedef long long LL;int Count(int n){    int cnt = 0;    while(n)    {        cnt += n / 5;        n /= 5;    }    return cnt;}int Two(int l, int r, int m){    int ans = 0;    while(r >= l)    {        int mid = (l + r) >> 1;        int res = Count(mid);        if(res < m)            l = mid + 1;        else if(res >= m) {            r = mid - 1;            ans = mid;        }    }    return ans;}const int MAXN = 1e9;int main(){    int m; cin >> m;    int l = 1, r = MAXN;    int L = Two(l, r, m), R = Two(l, r, m+1);    //cout << L << " " << R << endl;    if(L == 0 || Count(R-1) != m) cout << 0 << endl;    else {        cout << R - L << endl;        for(int i = L; i <= R-1; i++) {            if(i > L) cout << " ";            cout << i;        }        cout << endl;    }    return 0;}



0 0