100的階乘后面有多少個(gè)0

#include <bits/stdc++.h>

using namespace std;

bool IsPrime(int x){

if(x == 2 || x == 3)

return true;

if(x % 6 != 1 && x % 6 != 5)

return false;

int x_sqrt = (int)sqrt(x);

for(auto i = 5;i <= x_sqrt;i+=6){

if(x % i == 0 || x % (i+2) == 0)

return false;

}

return true;

}

int GetNextFactor(int factor){

if(factor == 2)

return 3;

int f;

for(f = factor + 2;true;f += 2){

if(IsPrime(f))

return f;

}

return -1;

}

/*因式分解*/

void func(int x,map<int,int> &ret){

int factor = 2;

while(x != 1){

if(x % factor == 0){

++ret[factor];

x /= factor;

}

else{

factor = GetNextFactor(factor);

}

}

}

int main(){

int n;

while(cin >> n){

/*因式分解后2的個(gè)數(shù)和5的個(gè)數(shù)*/

int num2 = 0,num5 = 0;

map<int,int> ret;

for(auto i = 2;i <= n;++i){

ret.clear();

func(i,ret);

for(auto it = ret.begin();it != ret.end();++it){

if(it->first == 2)

num2 += ret[it->first];

if(it->first == 5)

num5 += ret[it->first];

}

}

cout<<min(num2,num5)<<endl;

}

return 0;

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容