二分+阶乘(看质因数的个数是否够)
详细看大佬的博客:
https://blog.nowcoder.net/n/aa5ff9efa80440c897a9aaae4401a467?f=comment
#include<iostream> #include<math.h> #include<cstring> using namespace std; typedef long long ll; const int maxn=1e5+1; int num[maxn]; int sum[maxn]; ll k; bool judge(ll x){ for(int i=1;i<=k;i++){ ll n=x,sm=0; while(n){ sm+=n/num[i]; n/=num[i]; } if(sm<sum[i])return false; }return true; } int main(){ int t;ll p; cin>>t; while(t--){ cin>>p; memset(sum,0,sizeof sum); k=0; ll tp=p; for(int i=2;i*i<=tp;i++){ if(tp%i==0){ num[++k]=i; while(tp%i==0){ sum[k]++; tp/=i; } } }if(tp!=1){ num[++k]=tp; sum[k]++; } // for(int i=1;i<=k;i++){ // cout<<num[i]<<" "<<sum[i]<<endl; // } ll l=1,r=p; while(l<=r){ ll mid=(l+r)>>1; //cout<<mid<<" "<<l<<" "<<r<<endl; if(judge(mid)){ r=mid-1; }else{ l=mid+1; } }cout<<r+1<<endl; } return 0; }