Pagini recente » Cod sursa (job #2794862) | Cod sursa (job #3120501) | Cod sursa (job #1077257) | Cod sursa (job #776527) | Cod sursa (job #344329)
Cod sursa(job #344329)
#include <stdio.h>
#include <math.h>
#define Pmax 44730
#define Nmax 50005
const int Vmax = sqrt(Pmax);
int p[Nmax],prim[Nmax],e[Nmax],B[Nmax];
int x,q,i,max;
int V1,V2;
void read(){
freopen("gfact.in","r",stdin);
freopen("gfact.out","w",stdout);
scanf("%d%d",&x,&q);
}
void ciur(){
int i,j;
V2=sqrt(x);
for(i=2;i<=V2 && x>1 ;++i)
if(p[i]==0){
for(j=i*i; j<=V2 && x>1 ; j+=i)
p[i]=1;
if(x % i ==0){
prim[++prim[0]]=i;
while(x % i == 0 ) x/=i, ++e[prim[0]];
}
}
if(x>1) prim[++prim[0]]=x, e[prim[0]]=1;
}
int numar(int m,int i){
int p=prim[i]; int sol=0;
while( m >= p){
sol += m/p;
p *= prim[i];
}
return sol;
}
int caut_bin(int l,int r,int i){
int m,ret=0;
while(l<=r){
m=l+(r-l)/2;
if( numar(m*prim[i],i) >=e[i]*q ){
ret=m;
r=m-1;
}
else l=m+1;
}
return ret;
}
void work(){
int i;
ciur();
for(i=1;i<=prim[0];++i){
B[i] = caut_bin(1,e[i]*q,i)*prim[i];
if( B[i] > max ) max=B[i];
}
printf("%d\n",max);
fclose(stdin); fclose(stdout);
}
int main(){
read();
work();
return 0;
}