Pagini recente » Cod sursa (job #2552076) | Cod sursa (job #1694617) | Cod sursa (job #1650672) | Cod sursa (job #1703590) | Cod sursa (job #330018)
Cod sursa(job #330018)
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 103
int a[8][N],v[N],num[N],max;
bool compar(const int &a,const int &b)
{
return (a<b);
}
void div(int x)
{
for(int i=1; i*x<N-2; ++i)
{
bool ok=false;
while (v[i*x]%x==0)
{
v[i*x]/=x;
ok=true;
}
if (ok)
++num[i*x];
}
}
void matrice()
{
for (int i=2; i<N-2; ++i)
v[i]=i;
for (int i=2; i<N-2; ++i)
if (v[i]>1)
div(i);
for (int i=2; i<N-2; ++i)
a[num[i]][++a[num[i]][0]]=i;
for (int i=1; i<=7; ++i)
sort(a[i]+1,a[i]+a[i][0]+1,compar);
}
void caut(int x, int t)
{
if (a[t][1]>x)
{
printf("0\n");
return;
}
int p=1,u=a[t][0],m;
while (p!=u)
{
m=(p+u)/2;
if (a[t][m]>=x)
u=m;
else
p=m+1;
}
if (a[t][p]>x)
printf("%d\n",a[t][p-1]);
else
printf("%d\n",a[t][p]);
}
void citire()
{
freopen("divprim.in","r",stdin);
freopen("divprim.out","w",stdout);
short int t;
scanf("%hd",&t);
while (t)
{
int n,k;
scanf("%d%d",&n,&k);
caut(n,k);
--t;
}
}
int main()
{
matrice();
citire();
return 0;
}