第四题 #include<bits/stdc++.h> using namespace std; int main(){ int n, m; cin >> n >> m; map<int, int> factor; for(int i = 2; i <= m; i++){ while(m % i == 0){ m /= i; factor[i]++; } } map<int, int> cnt; for(auto iter = factor.begin(); iter != factor.end(); iter++){ int fac = iter->first; int tmp = 0, cur = n; while(cur){ tmp += (cur / fac); cur /= fac; } cnt[fac] = tmp; } int res = INT_MAX; for(auto iter = factor.begin(); iter != factor.end(); iter++){ int key = iter->first, val = iter->second; //cout<<key<<" "<<val<<endl; res = min(res, cnt[key] / val); } cout<<res<<endl; return 0; }
点赞 评论

相关推荐

10-13 17:47
门头沟学院 Java
wulala.god:图一那个善我面过,老板网上找的题库面的
点赞 评论 收藏
分享
牛客网
牛客企业服务