nefu 118——n!后面有多少个0

来源:互联网 发布:信捷plc流程梯图编程 编辑:程序博客网 时间:2024/05/01 20:00

思路:计算n!的素因子分解中的5的幂

代码如下:

#include<iostream>#include<cstdio>using namespace std;int main(){    int m;    scanf("%d",&m);    while(m--){        int n;        scanf("%d",&n);        int tmp=5;        int ans=0;        while(tmp<=n){            ans=ans+n/tmp;            tmp=tmp*5;        }        printf("%d\n",ans);    }    return 0;}


0 0