Stay Hungry,Stay Foolish!

D - Factorial and Multiple -- ATCODER

D - Factorial and Multiple

https://atcoder.jp/contests/abc280/tasks/abc280_d

 

思路

 

 

 

 

Code

https://blog.csdn.net/wp_fxy/article/details/128179159

https://www.cnblogs.com/Lanly/p/16950858.html#d---factorial-and-multiple-abc280-d

#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
ll k;
map<ll,ll> mymap;
 
int main(){
    cin >> k;
    ll kk=k;
    for(ll i=2;i*i<=kk;++i){
        while(k%i==0){
            mymap[i]++;
            k/=i;
        }
    }
    if(k!=1)
      mymap[k]++;
    ll ans=0;
    for(map<ll,ll>::iterator it=mymap.begin();it!=mymap.end();++it){
        ll p=it->first,q=it->second;
        ll mans=0,cnt=0;
        while(cnt<q){
            mans+=p;
            ll m=mans;
            while(m%p==0){
                cnt++;
                m/=p;
            }
        }
        ans=max(ans,mans);
    }
    cout << ans << endl;
    return 0;
} 

 

posted @ 2022-12-07 10:21  lightsong  阅读(63)  评论(0编辑  收藏  举报
Life Is Short, We Need Ship To Travel