You are not logged in. Please login at www.codechef.com to post your questions!

×

# include<stdlib.h>

int main() { int x,y,t,a,b,ans,flag,i,j; scanf("%d",&t); while(t) { scanf("%d %d",&x,&y); a=x+y; if(a==2) { printf("1\n"); goto xy; } else if(a<5) { b=5-(a%10); printf("%d\n",b); goto xy; } else if(a<7) { b=7-(a%10); printf("%d\n",b); goto xy; } a=x+y+1;

    ab:
if(a%10<=1)
{
b=1-(a%10);
a=a+b;
for(j=1;;j++)
{for(i=3;i*i<=a;i++)
{
flag=0;
if(a%i==0)
{
flag=1;
break;
}

}
if(flag==0)
{
ans=a-x-y;
printf("%d\n",ans);
goto xy;
}
if(j%3==1 || j%3==0)
a+=2;
else if(j%3==2)
a+=4;
}
}

else if(a%10<=3)
{
b=3-(a%10);
a=a+b;
for(i=3;i*i<=a;i++)
{
flag=0;
if(a%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
ans=a-x-y;
printf("%d\n",ans);
goto xy;
}
a+=4;
for(i=3;i*i<=a;i++)
{
flag=0;
if(a%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
ans=a-x-y;
printf("%d\n",ans);
goto xy;
}
a+=2;
for(i=3;i*i<=a;i++)
{
flag=0;
if(a%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
ans=a-x-y;
printf("%d\n",ans);
goto xy;
}
a+=2;
goto ab;
}

else if(a%10<=7)
{
b=7-(a%10);
a=a+b;
for(i=3;i*i<=a;i++)
{
flag=0;
if(a%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
ans=a-x-y;
printf("%d\n",ans);
goto xy;
}
a+=2;
for(i=3;i*i<=a;i++)
{
flag=0;
if(a%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
ans=a-x-y;
printf("%d\n",ans);
goto xy;
}
a+=2;
goto ab;
}

else if(a%10<=9)
{
b=9-(a%10);
a=a+b;
for(i=3;i*i<=a;i++)
{
flag=0;
if(a%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
ans=a-x-y;
printf("%d\n",ans);
goto xy;
}
a+=2;
goto ab;
}
xy:
t--;
}
return 0;


}

asked 26 Jun '14, 02:47

265615
accept rate: 0%

 1 Your algorithm seems to be wrong. Take a look at this code.This is my code. I think you will get the idea. It is easy and for more details check this editiorial answered 26 Jun '14, 13:06 3★bipin2 3.1k●25●46●71 accept rate: 8% hello! i have modified my question..... this code is for farmer feb... please help! (26 Jun '14, 23:38) :D let me look. hehe after reading the code i was like o.O :P (27 Jun '14, 08:30) bipin23★
 1 One advice that i can give you is, (i hope that you are just new to the world of programming) it is better not to use 'goto' in your code. it is not a good practice as you go further in the world of programming. You will not be able to de-bug your code easily. Take a look at this post I wish you all the success in the world of programming :) answered 27 Jun '14, 09:05 3★bipin2 3.1k●25●46●71 accept rate: 8%
 1 Here is your debugged code. I have made some major changes over there. But i have commented it very well so that you will understand it well. If you have any-doubt you are free to ask me :) Happy Coding answered 27 Jun '14, 09:07 3★bipin2 3.1k●25●46●71 accept rate: 8% If you understood my answer can you please accept it so that we can close the question ? :) (27 Jun '14, 18:05) bipin23★
 toggle preview community wiki:
Preview

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,919
×21

question asked: 26 Jun '14, 02:47

question was seen: 727 times

last updated: 27 Jun '14, 18:05