#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int seachsuzhu(int a)
{
int i,j;
int mark = 1;
int su;
int suadd,sudec;
for(i=a;mark;i++)
{
for(j=2;j<=sqrt(i);j++)
{
if(i%j == 0)
{
mark = 1;
break;
}
else{
suadd = i;
mark = 0;
}
}
}
mark = 1;
for(i=a;mark;i--)
{
for(j=2;j<i;j++)
{
if(i%j == 0)
{
mark = 1;
break;
}
else{
sudec = i;
mark = 0;
}
}
}
su= abs(suadd-a)>abs(sudec-a)?sudec:suadd;
printf("%d\n",su);
return 0;
}
int main()
{
int N;
int a;
scanf("%d",&N);
if(N>5)
{
return -1;
}
while(N--)
{
scanf("%d",&a);
if(a ==1 || a ==2)
{
printf("2\n");continue;
}
seachsuzhu(a);
}
return 0;
}
#include<math.h>
#include<stdlib.h>
int seachsuzhu(int a)
{
int i,j;
int mark = 1;
int su;
int suadd,sudec;
for(i=a;mark;i++)
{
for(j=2;j<=sqrt(i);j++)
{
if(i%j == 0)
{
mark = 1;
break;
}
else{
suadd = i;
mark = 0;
}
}
}
mark = 1;
for(i=a;mark;i--)
{
for(j=2;j<i;j++)
{
if(i%j == 0)
{
mark = 1;
break;
}
else{
sudec = i;
mark = 0;
}
}
}
su= abs(suadd-a)>abs(sudec-a)?sudec:suadd;
printf("%d\n",su);
return 0;
}
int main()
{
int N;
int a;
scanf("%d",&N);
if(N>5)
{
return -1;
}
while(N--)
{
scanf("%d",&a);
if(a ==1 || a ==2)
{
printf("2\n");continue;
}
seachsuzhu(a);
}
return 0;
}