include <stdio.h>
int main() { int i,j,flag[2000],temp,num1,num2,temp2,val,rept; for(i=1;i<1000;i++) flag[i]=1; flag[1]=0; //the 32 acts as a handle on the number of primes that there can be for(j=2;j<44;j++) {
//check if the current nummber is prime
if(flag[j]==1)
{
//now divide rest of the numbers beginning with this prime
temp=2*j;
while(temp<2000)
{
flag[temp]=0;
temp+=j;
}
//the numners which havent been crossed are primes
}
}
/* for(i=1;i<1000;i++)
{
if(flag[i]== 1)
printf("%d \n",i);
}
*/
//printf("\nenter the repetetions");
scanf("%d",&rept);
if(rept >1000)
{
//printf("incorrect input");
return 0;
}
while(rept !=0)
{
//printf("Enter the two numbers \n");
scanf("%d %d",&num1,&num2);
temp2=num1+num2;
if(num1 >1000 || num2>1000)
{
//printf("incorrect input");
return 0;
}
val=temp2+1;//since otherwise it would give the answer as 0 when we have a sum leading into a prime
while(flag[val]!=1)
val++;
//when the loop breaks we get the first prime number of our case
printf( "%d \n",(val-temp2));
rept--;
}
fflush(stdin);
getchar();
return 0;
}