[51nod]1003 阶乘后面0的数量 【数学题】

我们知道,10的因子是2和5,那么我们就求出N!中2的因子和5的因子数,取个小的就是答案,因为N!中5这个质因子肯定少于2,那么就直接求5这个质因子个数就可以了。

#include<cstdio>
using namespace std;
int n;
int get(int x,int y){
    int sum=0;
    for(;x;x/=y) sum+=x/y;
    return sum;
}
int main(){
    scanf("%d",&n);
    printf("%d\n",get(n,5));
    return 0;
} 
posted @ 2018-04-10 14:14  XSamsara  阅读(126)  评论(0)    收藏  举报