abc--280--D

D - Factorial and Multiple

题目大意

找到一个最小的n,使得n的阶乘能整除k

思路

将它化为一堆的质数,然后满足这些质数至少需要多大的数
最后这个找最大的数的时候,直接暴力就可以了,因为不会有很多个质数

代码
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define TT int _=read();while(_--)
#define int long long
//#define double long double
#define endl '\n'
const int inf=1e18;
const int M=1e6+5;
 
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    return x*f;
}
 
inline void print(int x) {
    if(x<0){putchar('-');x=-x;}
    if(x/10)print(x/10);
    putchar(x%10+'0');
}
 
int a[M];
char s[M],ss[M];
vector<int>v;
//首先计算质因子,然后呢
map<int,int>mp;
 
signed main() {
    int k=read();
    for(int i=2;i*i<=k;i++)
        while(k%i==0)k/=i,mp[i]++;
    if(k!=1)mp[k]++;
    deque<int>q;
    int ans=0;
    for(auto [x,y]:mp) {
        int cnt=0,i;
        for(i=1;i<=100;i++) {
            int tmp=i;
            cnt++;
            while(tmp%x==0)tmp/=x,cnt++;
            if(cnt>=y)break;
        }//寻找一下满足这个质数的数量,至少需要多大的数
        ans=max(ans,i*x);
    }
    cout<<ans;
    return 0;
}
posted @ 2022-12-04 11:26  basicecho  阅读(25)  评论(0)    收藏  举报