【Henu ACM Round #13 D】A Trivial Problem

【链接】 我是链接,点我呀:)
【题意】

在这里输入题意

【题解】

1*2*3*...*n中末尾0的个数 只会由素因子2和5的个数决定且等于 Min{cnt[2],cnt[5]} 且素因子2的个数一定会比5多; 所以n!的末尾0的个数 等于for (int i = 1;i <= n;i++)中所有i的5因子的个数和 枚举一下就好

【代码】

#include <bits/stdc++.h>
using namespace std;

const int N = 1e7;

int n;
vector<int> v;

int main(){
	#ifdef LOCAL_DEFINE
	    freopen("rush_in.txt", "r", stdin);
	#endif
	ios::sync_with_stdio(0),cin.tie(0);
	cin >> n;
	int cnt5 = 0;
    for (int i = 1;i <=N;i++){
        int j = i;

        while (j%5==0){
            j/=5;
            cnt5++;
        }
        if (cnt5==n)
            v.push_back(i);

    }
    cout <<(int)v.size()<<endl;
    for (int i = 0;i < (int)v.size();i++){
        cout <<v[i]<<' ';
    }
	return 0;
}
posted @ 2018-01-23 12:10  AWCXV  阅读(98)  评论(0编辑  收藏  举报