Timer is Running

Collection of pens
Submissions: 2361   Accuracy:


  Difficulty: Easy   Marks: 2

Everyone have some habits to collect one thing or the other. Harshit also has the craze to collect pens but in 3 piles. In first pile, he collected A pens and in the second pile, he collected B pens but in the third and the last pile , he think of something different. He decided to collect only the minimum number of pens in third pile so that the sum of pens in the three piles will give him a prime number. Note: there should be atleast one pen in the third pile.


First line contains the test cases,t. Then T test cases follow. Each line of the test case two space separated values A,B ie. number of pens in first and
second pile respectively.

Print the minimum number of pens that should be there in the third pile so that sum of all three piles produces a prime number.



1 3                 
4 3



In first case,Harshit put one pen in first pile and 3 pens in second pile which give 4 as a sum.So if he adds one pen in the third pile, the sum will yield a prime number ie.5
Therefore the answer is 1.
Similarly for other test case



** For More Input/Output Examples Use 'Expected Output' option **

Contributor: vaibhav garg
Author: justrelax

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.