本题求m的最大多少次幂是 n!的因子;
也就是质因子分解 n!中某一质因子个数与m中质因子个数比的最小值。
#include <iostream>
#include <cstring>
using namespace std;
int sign[10010];
int pri[10010];
int tot;
int e2[10010][1500],e1[10010][1500];
void getpri (){
memset (sign,0,sizeof sign);
sign[0]=sign[1]=1;
for (int i=2;i*i<10000;i++){
if (!sign[i]){
for (int j=i*i;j<10000;j+=i){//cout<<"error";
sign[j]=1;
}
}
}
tot=0;
for (int i=2;i<10000;i++)
if (!sign[i])
pri[tot++]=i;//cout<<i<<" ";
}
int main (){
int t;
int n,m,temp,ans;
getpri ();//cout<<tot;
memset (e2,0,sizeof e2);
memset (e1,0,sizeof e1);
for (int i=2;i<=10000;i++){
temp=i;
for (int j=0;j<tot;j++){
while (temp%pri[j]==0){
e2[i][j]++;
temp/=pri[j];
}
e1[i][j]=e1[i-1][j]+e2[i][j];
}
}
cin>>t;
for (int casenum=1;casenum<=t;casenum++){
cin>>m>>n;
ans=1000000;
for (int j=0;j<tot;j++){
if (e2[m][j])
ans=min (ans,e1[n][j]/e2[m][j]);
}//cout<<e1[0]<<" "<<e2[0]<<" "<<n%pri[0];
cout<<"Case "<<casenum<<":"<<endl;
if (ans==1000000||ans==0)
cout<<"Impossible to divide"<<endl;
else
cout<<ans<<endl;
}
return 0;
}
UVA 10780 Again Prime? No Time.,布布扣,bubuko.com
UVA 10780 Again Prime? No Time.
原文:http://www.cnblogs.com/gfc-g/p/3848874.html