2018sjtu-n阶乘尾部0的个数
考察分解质因数的思想
其中要求结尾0的个数,即求分解出的质因数中2和5的个数的最小值。
只需要不断地/2(/5)并计数即可
#include <iostream>
#include <algorithm>
using namespace std;
int n;
int cnt2,cnt5;
int main()
{
while(cin>>n)
{
cnt2=cnt5=0;
int temp=n;
while(temp){
cnt5+=temp/5;
temp/=5;
}
temp=n;
while(temp)
{
cnt2+=temp/2;
temp/=2;
}
cout<<min(cnt2,cnt5)<<endl;
}
return 0;
}