Pagini recente » Cod sursa (job #300465) | Cod sursa (job #1820602) | Cod sursa (job #3162253) | Cod sursa (job #1742173) | Cod sursa (job #896488)
Cod sursa(job #896488)
#include<cstdio>
const int N=1000001,D=8;
int ciur[N],p[N],m[N][D];
void prec(){
int i,j,k=0;
p[0]=1;
for(i=2;i<=N;i++)
if(!ciur[i]){
p[k+1]=p[k]*i;
k++;
for(j=i;j<N;j+=i)
ciur[j]++;
}
}
void maxs(){
int i,j;
for(i=2;i<N;i++){
for(j=0;j<D;j++)
m[i][j]=m[i-1][j];
m[i][ciur[i]]=i;
}
}
int main(){
int k,t,i,n;
freopen("divprim.in","r",stdin);
freopen("divprim.out","w",stdout);
prec();
maxs();
scanf("%d",&t);
for(i=1;i<=t;i++){
scanf("%d%d",&n,&k);
if(k>=D || p[k]>n)
printf("0\n");
else
printf("%d\n",m[n][k]);
}
return 0;
}