Assume the cricket ground to be an infinite grid and there can be more than 11 players in a team. It is known that the batsmen stand at the point (0,0). The field placement follows the following pattern
1st fielder is to be placed at 1 step to the east of batsman.
2nd fielder is to be placed at 2 steps to the north of 1st fielder
3rd fielder is to be placed at 3 steps to the West of 2nd fielder
4th fielder is to be placed at 4 steps to the south of 3rd fielder
5th fielder is to be placed at 5 steps to the East of 4th fielder
6th fielder is to be placed at 6 steps to the North of 5th fielder
And so on….
The fielders can be placed at only these positions and no where else…i.e at (1,0) , (1,2) , ( -2,2) , (-2,-2) and so on.
In the CWC final 2015, Michael Clarke realizes that to win the match, it is crucial to get Brendon McCullum out early . After a deep study, it was found that Brendon often gets out by giving catch to fielders standing at prime numbered positive positions of x on X-Y plane on the grid . He has decided that he will himself take the catch. Now, Clarke is confused and wants your help to win the match. Find out for him whether Clarke has positioned himself at any of the catching positions or not.
Input :
Input starts with T denoting the number of test cases.
Next T lines contains space separated coordinates x,y which are coordinates of point where Clarke has positioned himself.
Output :
If the position is wicket taking , then print “YES” without quotes else Print “NO”.
Constraints :
1 ≤ T ≤ 100
1 ≤ x,y ≤ 10^5
Problem Setter : Adesh Kala
SAMPLE INPUT
4
3 3
3 4
5 5
6 6
SAMPLE OUTPUT
NO
YES
NO
NO
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
We need to parse the problem. The fielders are placed according to a pattern: batsman at (0,0). First fielder placed at 1 step east of batsman -> (1,0). Second fielder: 2 steps north of first fielder -> (1,0)+(0,2)=(1,2). Third fielder: 3 steps west of second -> (1-3,2)=(-2,2). Fourth fielder: 4 steps south of third -> (-2,2-4)=(-2,-2). Fifth fielder: 5 steps east of fourth -> (-2+5,-2)=(3,-2). Sixth: 6 steps north of fifth -> (3,4). Seventh: 7 steps west -> (3-7,4)=(-4,4). Eighth: 8 steps south -> (-4,4-8)=(-4,-4). Ninth: 9 steps east -> (5,-4). Tenth: 10 steps north -> (5,6). Eleventh: 11 steps west -> (-6,6). Twelfth: 12 steps south -> (-6,-6). So the pattern continues.
We have an infinite list of fielders positions (the ones placed by this pattern). The note: "The fielders can be placed at only these positions and no where else…i.e at (1,0) , (1,2) , ( -2,2) , (-2,-2) and so on."
Now: "Brendon often gets out by giving catch to fielders standing at prime numbered positive positions of x on X-Y plane on the grid." Let's interpret: "prime numbered positive positions of x" likely means that the x-coordinate is a prime number and also positive. But also "on the X-Y plane on the grid". So the catching positions are those fielders whose x-coordinate is a prime number and positive. However, note that the fielders' positions might have negative x, etc. Only those with x > 0 and prime are "catching positions". Clarke wants to know if his position (x,y) (given input) is one of those catching positions? Or more precisely: "Find out for him whether Clarke has positioned himself at any of the catching positions or not." So given (x,y), determine if (x,y) is one of the fielder positions that is a "catching position", i.e., a fielder with x positive prime.
Thus we need to generate all fielder positions according to the spiral-like pattern, check if any such position has x>0 and prime, and then see if given coordinates match such a position.
But note: The pattern is like a square spiral but with steps increasing each time, starting at (0,0) and moving east 1, north 2, west 3, south 4, east 5, north 6, west 7, south 8, ... So it's like a path, and each step places a fielder at the new location. Actually first fielder is at (1,0), second at (1,2), third at (-2,2), fourth at (-2,-2), fifth at (3,-2), sixth at (3,4), seventh at (-4,4), eighth at (-4,-4), ninth at (5,-4), tenth at (5,6), eleventh at (-6,6), twelfth at (-6,-6), etc.
Thus the positions follow a pattern: After each even number of steps? Let's analyze coordinates after each move.
Define step k (starting at 1) with length k, direction cycles: East, North, West, South, East, North, West, South,...
We start at batsman at (0,0). Then after move 1 (east), we are at (1,0) -> fielder 1.
After move 2 (north), we are at (1,2) -> fielder 2.
After move 3 (west), we are at (-2,2) -> fielder 3.
After move 4 (south), we are at (-2,-2) -> fielder 4.
After move 5 (east), we are at (3,-2) -> fielder 5.
After move 6 (north), we are at (3,4) -> fielder 6.
After move 7 (west), we are at (-4,4) -> fielder 7.
After move 8 (south), we are at (-4,-4) -> fielder 8.
After move 9 (east), we are at (5,-4) -> fielder 9.
After move 10 (north), we are at (5,6) -> fielder 10.
After move 11 (west), we are at (-6,6) -> fielder 11.
After move 12 (south), we are at (-6,-6) -> fielder 12.
So the positions for odd moves (east/west) and even moves? But more importantly, note that after every 4 moves, we complete a "loop" and the step length increases by 4? Actually pattern: After move 4, we are at (-2,-2). After move 8, we are at (-4,-4). After move 12, we are at (-6,-6). So after moves that are multiples of 4, we end at (-n,-n) where n = move/2? Let's see: move 4 -> (-2,-2) = (- (4/2?), 4/2 =2). Move 8 -> (-4,-4) = (-8/2? 8/2=4). Move 12 -> (-6,-6) = (-12/2=6). So after move m where m = 4k, we are at (-2k, -2k)? Actually 41=4 -> -2; 42=8 -> -4; 43=12 -> -6. So it's -(2k)?? For k=1,2,3 => -2, -4, -6. So it's -(2k) = - (m/2)? Because m/2 = 2k? For m=4k, m/2 = 2k => yes. So after move m = 4k, coordinates are (-2k, -2k). Similarly after move m=4k+1? Actually after move 5 (k=1, 41+1=5) we are at (3,-2) = (2k+1?, 2k? For k=1: (3, -2) = (21+1, -21) = (2k+1, -2k). After move 9 (k=2, 42+1=9) -> (5,-4) = (22+1, -4) = (2k+1, -2k). So after move 4k+1, coordinates are (2k+1, -2k). After move 4k+2: e.g., move 6 (41+2) -> (3,4) = (2k+1, 2k+2?) For k=1: (3,4) = (2k+1, 2k+2?) 2+2=4, yes. Move 10 (42+2=10) -> (5,6) = (5,6) => (2k+1, 2k+2?) k=2 => (5,6) yes. So after move 4k+2: (2k+1, 2k+2). After move 4k+3: e.g., move 7 (41+3) -> (-4,4) = (-2(k+1)? For k=1: -4? Actually pattern: (-(2k+2), 2k+2?) For k=1: (-4,4) = (-(21+2), 21+2) = (-4,4). For k=2: move 11 -> (-6,6) = (-(22+2), 2*2+2) = (-6,6). So after move 4k+3: (-(2k+2), 2k+2). After move 4k+4: ( - (2k+2), - (2k+2) )? But earlier we had after 4k move: (-2k, -2k). But for k starting from 1, 4k is 4,8,12,... we get (-2,-2), (-4,-4), (-6,-6). So after 4k: (-2k, -2k). But note that for k=0, move 0: (0,0). That's consistent: 0-> (0,0) = (-0,-0). So the pattern holds for k>=0.
Now, for each move i (i >= 1), the position of fielder i is given by above formulas based on i mod 4. But careful: The formulas we derived are for i = 4k, 4k+1, 4k+2, 4k+3. However we should verify for small k. Let's define k such that:
Case 1: i = 4k (k >= 1) -> position = (-2k, -2k). For i=4, k=1 -> (-2,-2) correct. i=8, k=2 -> (-4,-4) correct. i=12, k=3 -> (-6,-6) correct.
Case 2: i = 4k+1 (k>=0) -> position = (2k+1, -2k). For i=1, k=0 -> (1,0) correct. i=5, k=1 -> (3,-2) correct. i=9, k=2 -> (5,-4) correct. i=13, k=3 -> (7,-6) correct? Let's simulate: after 12 at (-6,-6), move 13 east length 13 -> (-6+13,-6) = (7,-6) yes.
Case 3: i = 4k+2 (k>=0) -> position = (2k+1, 2k+2). For i=2, k=0 -> (1,2) correct. i=6, k=1 -> (3,4) correct. i=10, k=2 -> (5,6) correct. i=14, k=3 -> (7,8) correct? After 13 at (7,-6), move 14 north 14 -> (7, -6+14) = (7,8) yes.
Case 4: i = 4k+3 (k>=0) -> position = (-(2k+2), 2k+2). For i=3, k=0 -> (-2,2) correct. i=7, k=1 -> (-4,4) correct. i=11, k=2 -> (-6,6) correct. i=15, k=3 -> (-8,8) correct? After 14 at (7,8), move 15 west 15 -> (7-15,8) = (-8,8) yes.
Thus the positions are parameterized by k (nonnegative integer) and the type (mod 4). So all fielder positions are exactly the set:
S = { (2k+1, -2k) : k >= 0 } ∪ { (2k+1, 2k+2) : k >= 0 } ∪ { (-(2k+2), 2k+2) : k >= 0 } ∪ { (-2k, -2k) : k >= 1 }? But note for k=0, (-0,-0) is (0,0) which is batsman, not a fielder? Actually the batsman is at (0,0), not a fielder. The pattern of fielders starts from move 1. So the set for the "negative quadrant" type i=4k (k>=1) gives fielders at (-2,-2), (-4,-4), ... So it's for k>=1. Similarly, maybe also consider the case i=4k+3 includes k=0 giving (-2,2). That's okay.
Now, we need to find catching positions: those fielders which stand at prime numbered positive positions of x on X-Y plane. The phrase: "prime numbered positive positions of x" likely means the x-coordinate is a prime number and also positive (i.e., x > 0 and prime). So among all fielders, those with x > 0 and prime are catching positions. The question: Clarke wants to know if his position is one of those catching positions. So for each test case (x,y), we need to check if (x,y) is a fielder and x is prime > 0. However note: it says "prime numbered positive positions of x" might be interpreted as the fielder's index (i.e., the fielder number) is prime? But the phrase "positions of x on X-Y plane" suggests x coordinate. Also "prime numbered positive positions of x" is ambiguous: could be "prime-numbered positive positions" meaning the positions whose x is prime? Usually "prime numbered" might refer to something like "prime-numbered positions" meaning the 2nd, 3rd, 5th, etc., positions. However here "positive positions of x on X-Y plane" suggests x coordinate positive and prime. Let's check sample: Input: (3,3) => output NO. (3,4) => YES. (5,5) => NO. (6,6) => NO. Let's test our interpretation: We need to see if (3,4) is a fielder and x=3 is prime and positive -> is (3,4) a fielder? Yes, it's fielder 6 (or also fielder? Actually (3,4) appears in the list: it's fielder 6. So that would be catching. (3,3) is not a fielder (from our set, positions: (3,-2), (3,4), etc., not (3,3). So NO. (5,5) not a fielder (we have (5,-4), (5,6), (5,?) maybe (5,5) is not in set). So NO. (6,6) not a fielder: we have (6?) we have (-6,6) and (6?) Actually after further moves: (7,8), (-8,8), (-8,-8), (9,-8), (9,10),... No (6,6). So NO. So sample matches.
What about other possible catching positions? For example (1,0) -> x=1 not prime (1 is not prime). So not catching. (1,2) -> x=1 not prime. (3,-2) -> x=3 prime but y negative? Does y matter? The condition says "prime numbered positive positions of x" meaning only x positive prime; y can be any? It doesn't say positive y, just positive x. So (3,-2) should be a catching position? But maybe the sample doesn't include that. Let's check if (3,-2) is a fielder: yes, fielder 5. x=3 prime, positive. So according to interpretation, it would be a catching position. But the sample doesn't have such a test. However, the problem might have implicitly considered only positions where x is positive and y positive? The phrase "positive positions of x" could be interpreted as "positions with positive x coordinate". Not necessarily y positive. So (3,-2) qualifies. But maybe the problem expects that Clarke positions himself at fielders where x is positive prime and also perhaps the fielder index? However we need to be careful: The sample only tests a case that is YES (3,4). That's consistent with our interpretation.
But could there be other points that are fielders with positive prime x but also maybe duplicate? Let's enumerate some fielders with positive x: From set (2k+1, -2k) for k>=0: x = 2k+1 which is odd >=1; y = -2k <=0 (non-positive). For k=0: (1,0) x=1 (not prime). k=1: (3,-2) x=3 prime. k=2: (5,-4) x=5 prime. k=3: (7,-6) x=7 prime. k=4: (9,-8) x=9 not prime. k=5: (11,-10) x=11 prime. So many.
From set (2k+1, 2k+2): x=2k+1 (odd >=1); y=2k+2 (even >=2). For k=0: (1,2) x=1 not prime. k=1: (3,4) x=3 prime. k=2: (5,6) x=5 prime. k=3: (7,8) x=7 prime. k=4: (9,10) x=9 not prime. So many.
Also from other sets, x negative or zero, so not positive.
Thus catching positions are those fielder positions from the two sets above where x is prime. So basically fielder positions of the forms:
(p, - (p-1) )? Since x=2k+1, y = -2k = -(x-1) because 2k = x-1, so y = -(x-1). For x odd >1? Actually for (2k+1, -2k): y = -(x-1). So positions: (prime odd, -(prime-1)). But note x=1 gives y=0, not prime anyway.
(p, p+1)?? For the other set: x=2k+1, y=2k+2 = x+1. So positions: (prime odd, prime+1). So both sets yield y determined by x.
Thus the catching positions are exactly points of the form (p, - (p-1)) and (p, p+1) where p is an odd prime? Actually x=prime and x must be odd? Since x=2k+1, x is odd. So prime must be odd (primes >2 are odd; 2 is even but 2 is prime but x=2 is even. Is x=2 possible as a fielder? Let's check if any fielder has x=2. From our formulas: x from positive sets is 2k+1, so always odd. So x=2 never appears. So prime 2 is not a catching position because no fielder has x=2. So catching positions are only for odd primes p.
Also note: p can be 1? not prime.
Thus the problem reduces: given (x,y) with 1 ≤ x,y ≤ 10^5 (actually constraints say 1 ≤ x,y ≤ 10^5). So y is also positive. That simplifies: y is between 1 and 10^5. So we only need to consider fielders with positive y, because input y is positive. Which set gives positive y? The set (2k+1, 2k+2) yields y = 2k+2 ≥ 2, positive. The set (2k+1, -2k) yields y negative (or zero for k=0, but y=0 not positive). So given y ≥ 1, only the second set (with y positive) is relevant. So the only possible catching positions with positive y are those where y = x+1 (since y = 2k+2, x=2k+1 => y = x+1). And x must be an odd prime.
But wait, is there any other fielders with positive y and positive x? Could there be fielders from later moves where x positive and y positive that are not captured by the (2k+1, 2k+2) pattern? Let's examine moves further: After move 6 we are at (3,4). After move 10 we are at (5,6). After move 14 we are at (7,8). So it's always (odd, even) with y = x+1. Also after move 18? Let's see pattern: move 14 (east? Actually after 14 north, we are at (7,8). Then move 15 west -> (-8,8) (x negative). Move 16 south -> (-8,-8). Move 17 east length 17 -> (9,-8) (x positive, y negative). Move 18 north length 18 -> (9,10) (x positive, y positive). Yes, that's (9,10): x=9 (not prime), y=10 = x+1. So indeed the pattern for moves that end with north direction: moves 2,6,10,14,18,... i.e., moves of the form 4k+2 produce (2k+1, 2k+2). So all fielders with both coordinates positive appear only in those moves. And no other fielders have both positive coordinates? What about after an east move? That yields y negative (or zero). After west move yields x negative. After south yields both negative. So indeed the only fielders with both x>0, y>0 are those from moves 4k+2. So given constraints x,y positive, we only need to consider that set. So the problem reduces to: For given (x,y), check if y = x+1 and x is an odd prime. Because x must be prime (and positive) to be a catching position.
But wait, is there any scenario where x positive prime but y not exactly x+1? Could there be a fielder with x positive prime and y positive but not equal x+1? Let's double-check the whole sequence: after move 6 we have (3,4). After move 10: (5,6). After move 14: (7,8). After move 18: (9,10). After move 22: (11,12). So indeed y = x+1. Also move 2: (1,2) but x=1 not prime. So yes. So for positive y, the only possible positions are (1,2), (3,4), (5,6), (7,8), (9,10), (11,12), ... In general (n, n+1) where n is odd. And we require n to be prime. So the catching positions (with both coordinates positive) are (3,4), (5,6), (7,8), (11,12), (13,14), (17,18), (19,20), (23,24), (29,30), (31,32), ... i.e., for each odd prime p, (p, p+1). But note: p=2 not odd, but x=2 is not a fielder because x=2 never appears. So primes are only odd primes. So the answer for a given (x,y) is YES if and only if y = x+1 and x is an odd prime.
Now check sample: (3,4): x=3 prime, y=4 = x+1 => YES. (5,5): y=5, x=5; y != x+1 => NO. (6,6): no. (3,3): no. So matches.
But note: The sample also includes NO for (5,5) and (6,6). (5,5) is not of the form (prime, prime+1). Good.
Now, what about (1,2)? x=1 not prime, so answer should be NO. But not in sample.
Now constraints: T up to 100, x,y up to 10^5. So we can precompute primes up to 10^5 and then for each test case, check if y == x+1 and x is prime.
But careful: The constraints say 1 ≤ x,y ≤ 10^5. So if x is prime and y = x+1, it's possible that y could be 10^5+1? But since x ≤ 10^5, x+1 ≤ 100001, which may exceed 10^5? Actually if x=100,000 (not prime) no; but if x is prime near 10^5, say 99991, then y = 99992, which is ≤ 100000? Actually 99992 ≤ 100000, ok. But if x=99991, y=99992, both within limits. If x=100003 not allowed because x ≤ 10^5. So maximum x is 100000, but the largest prime less than 100000 is 99991, so y = 99992 ≤ 100000. So y is within limit. So no overflow.
Thus simple solution: For each test case, if y == x+1 and isPrime(x) and x != 1 (since 1 is not prime), then YES else NO.
But wait: Could there be any fielder with x positive and y negative but still considered catching? But the problem asks: "Clarke has positioned himself at any of the catching positions or not." The input coordinates x,y are both positive as per constraints: 1 ≤ x,y ≤ 10^5. So we only consider positive coordinates. Thus any negative y positions are not relevant. So we only need to check positive y condition. But what if x positive prime and y negative? That would still be a catching position (since condition only says prime numbered positive positions of x, not that y positive). But since inputs y are always positive, that case will never appear. So our condition suffices.
But the problem statement says: "the fielders can be placed at only these positions and no where else…i.e at (1,0) , (1,2) , ( -2,2) , (-2,-2) and so on." So the positions are as described. The catching positions are those with prime numbered positive x. So any fielder whose x is prime and positive, regardless of y, is a catching position. But the input coordinates are limited to positive x,y (both from 1 to 10^5). So we only check those.
Thus answer is as above.
But wait: Could there be any fielder with x positive and y positive but not of the form (odd, odd+1)? Let's re-check the movement pattern: The path is a spiral that expands. Could there be any other moves that land on positive x and y besides the north moves (4k+2)? Let's list positions for first 20 moves:
So indeed the only positive-positive points are at moves 2,6,10,14,18,... which are all of the form 4k+2, giving (odd, odd+1). So it's consistent.
Thus we can implement.
But is there any nuance about "prime numbered positive positions of x"? Could it mean the index (fielder number) is prime? Let's examine that interpretation: "Brendon often gets out by giving catch to fielders standing at prime numbered positive positions of x on X-Y plane on the grid." The phrase "prime numbered positive positions of x" could be read as "prime-numbered positive positions of x" meaning the positions along the x-axis? Or "prime numbered positive positions" could be interpreted as "positions that are prime numbers and are positive on the x-axis"? Actually the wording is ambiguous. However sample clarifies: (3,4) is YES. If we interpret as fielder index prime, which fielders are at prime indices? Let's list fielder numbers and positions: 1:(1,0),2:(1,2),3:(-2,2),4:(-2,-2),5:(3,-2),6:(3,4),7:(-4,4),8:(-4,-4),9:(5,-4),10:(5,6),11:(-6,6),12:(-6,-6),13:(7,-6),14:(7,8),15:(-8,8),16:(-8,-8),17:(9,-8),18:(9,10),19:(-10,10),20:(-10,-10),... The prime indices: 2,3,5,7,11,13,17,19,... Their positions: 2:(1,2) (x=1 not prime), 3:(-2,2) (x=-2 not positive), 5:(3,-2) (x=3 prime positive? y negative), 7:(-4,4) (x negative), 11:(-6,6) (x negative), 13:(7,-6) (x=7 prime positive, y negative), 17:(9,-8) (x=9 not prime), 19:(-10,10) (x negative). So prime indices yield some positions with x positive prime: e.g., index 5 gives (3,-2) with x=3 prime; index 13 gives (7,-6) with x=7 prime; index 29? etc. But sample input includes (3,4) which is index 6, not prime. So if catching positions were defined by prime index, then (3,4) would not be catching (index 6 not prime). So that interpretation fails sample. So it's about x coordinate being prime.
Another interpretation: "prime numbered positive positions of x" could be positions on the X-axis? But (3,4) is not on x-axis. So no.
Thus correct: x-coordinate positive and prime.
Now implement: For each test case, read x and y. Check if y == x+1 and if x is prime. If yes, print "YES", else "NO".
Edge cases: x=2? But 2 is prime, but y would be 3 if y = x+1, (2,3). Is (2,3) a fielder? According to pattern, does any fielder have x=2? No, because x is always odd for positive fielders. So (2,3) would not be a fielder. But we can still check: is x prime? Yes. But is y = x+1? Yes. However, does (2,3) appear? From our set, x=2 never appears. So answer should be NO. Our condition will say YES if we only check x prime and y=x+1. But we must also ensure that (x,y) is actually a fielder position. For x=2, there is no fielder with x=2. So we need to incorporate that x must be odd (since all positive fielders have odd x). Actually from derived formulas: only fielders with both coordinates positive have x odd (2k+1). So if x is even and prime (2), then y = x+1 = 3, but no such fielder. So we need to check that x is odd. But does the condition "x positive prime" automatically imply x is odd (since only odd primes >2)? 2 is prime but even. So we must ensure that x is not 2? But is 2 considered a "prime numbered positive positions of x"? Possibly yes, but there is no fielder at x=2. So (2,3) would not be a catching position because it's not a fielder. The problem says: "Brendon often gets out by giving catch to fielders standing at prime numbered positive positions of x" meaning those fielders whose x is prime and positive. So a fielder must exist at that position. So if there is no fielder at (2,3), it's not a catching position. So our check must verify that the point (x,y) is a fielder and x prime. Our derived condition y = x+1 and x odd prime is correct because for positive x,y, fielder iff y=x+1 and x odd. So we need x odd and prime. So check: y == x+1 and isPrime(x) and x%2==1 (i.e., x odd). But since the only prime even is 2, we can just check that x != 2. However, there is also the possibility x=1? Not prime. So it's safe: if x is prime and >2, it's odd automatically. So we can just check if x is prime and x>2 (since 2 is prime but not odd, and not a fielder). So condition: y == x+1 and isPrime(x) and x != 2.
But is there any fielder with x=2? Let's double-check the pattern for positive x,y: it's always odd. Could there be a fielder with positive x and y from another type? For instance, after move 5, we have (3,-2) has x=3 odd. After move 9, (5,-4) x=5 odd. After move 13, (7,-6) x=7 odd. After move 17, (9,-8) x=9 odd. So all positive x are odd. So yes, x must be odd.
Thus final condition: y == x+1 and isPrime(x) (with x > 1). Since prime implies >1. For x=2, isPrime true but y would be 3, but not a fielder, so answer NO.
Alternatively, we can also verify by checking that x is odd and prime, and y = x+1.
Now constraints up to 10^5, so we can precompute sieve up to 100000.
Implementation steps:
Precompute boolean array prime[0..100000] (or 100001) using sieve.
Then for each test case, read x,y.
If y == x+1 and prime[x] and x != 2? Actually prime[2] is true but will be excluded automatically because y == x+1? For (2,3) would satisfy y==x+1, but we must reject. So either check x%2==1 or x!=2. Since prime[2] is true, we need to specifically reject x=2. So condition: if y == x+1 and isPrime(x) and x != 2 -> YES else NO.
But is there any prime that is even besides 2? No. So just x != 2. But also consider x=1? isPrime[1]=false, so no.
Thus we can just do: if (y == x+1 && isPrime(x) && x != 2) print YES else NO.
Alternatively, we could also directly check if x is odd prime: if (y == x+1 && isPrime(x) && (x%2==1)). That automatically excludes 2.
Now we must also consider if any other fielder with positive y and x but not of that form? The sample ensures only that. But confirm with larger moves: Move 22 (4*5+2) would be (11,12). So yes.
Thus answer is as above.
Now, what about (1,2)? isPrime(1)=false so NO.
Now the problem statement: "Clarke is confused and wants your help to win the match. Find out for him whether Clarke has positioned himself at any of the catching positions or not." So he gives his coordinates. So we output YES if it's a catching position (fielder with x prime positive). For positive coordinates, that reduces to above.
But wait: Could there be a fielder with positive x and prime x but y negative, and Clarke might position himself there? But constraints say y positive. So that scenario won't be queried. So we are fine.
Thus solution is simple.
But before finalizing, let's double-check the pattern derivation thoroughly to ensure there is no oversight: The pattern described: "1st fielder is to be placed at 1 step to the east of batsman. 2nd fielder is to be placed at 2 steps to the north of 1st fielder. 3rd fielder is to be placed at 3 steps to the West of 2nd fielder. 4th fielder is to be placed at 4 steps to the south of 3rd fielder. 5th fielder is to be placed at 5 steps to the East of 4th fielder. 6th fielder is to be placed at 6 steps to the North of 5th fielder. And so on…" So the position of the nth fielder is after moving n steps from the batsman? Actually careful: The batsman is at (0,0). Then they place the 1st fielder at 1 step east of batsman: that is the position (1,0). Then they place the 2nd fielder at 2 steps north of the 1st fielder: so from (1,0), go north 2 -> (1,2). So the 2nd fielder is at (1,2). Then the 3rd fielder at 3 steps west of 2nd fielder: from (1,2), go west 3 -> (-2,2). So the fielder positions are the endpoints of each move. So indeed the nth fielder is at the location after the nth move. So our derivation stands.
Thus our formula for positions after each move is correct.
Now verify some points: (3,4) is 6th fielder, correct. (5,6) is 10th. (7,8) is 14th. So pattern holds.
Now confirm that these points indeed satisfy y = x+1. Yes.
Now confirm that x is prime for catching: So we need to check if given (x,y) is such that x is prime and y = x+1. So as above.
Now we should also consider the possibility that the catching positions include those with positive x prime regardless of y, and if y positive but not x+1? Could there be a fielder with positive x and positive y where y != x+1? Maybe if the starting point wasn't (0,0) but it is. Let's think: Could there be a fielder at (3,2)? Suppose after move something else? No. So it's fine.
Now consider if x is prime and y negative? That would also be catching, but y positive so won't be queried.
Thus answer logic.
Now the problem setter might have intended this simple logic. But we need to check if there is any nuance: The phrase "prime numbered positive positions of x" could be interpreted as "positions where x is a positive prime number". That's what we did.
Now consider whether (1,0) is a prime x? No. (1,2): no. So correct.
Now the constraints 1 ≤ x,y ≤ 10^5 means they are positive integers. So our solution fits.
Now we should also consider the possibility of multiple test cases up to 100, which is trivial.
Now code: Use sieve to compute prime up to 100000. Then for each query, check.
But is there any possibility of x = 1? Not prime, so NO.
Now consider edge case: x=10^5, y=100001, but y ≤ 10^5, so y cannot be 100001. So such case won't occur.
Now for x=2, y=3 (both within range). According to our logic, we would output NO. But is that correct? Let's manually check if there is a fielder at (2,3). In our list, does (2,3) ever appear? The fielders: 1:(1,0),2:(1,2),3:(-2,2),4:(-2,-2),5:(3,-2),6:(3,4),7:(-4,4),8:(-4,-4),9:(5,-4),10:(5,6),... So no (2,3). Could later moves produce (2,3)? Let's think. The coordinates are always odd for positive x in north moves, but perhaps from east moves? East moves give y negative or zero. West moves x negative. South moves both negative. So no (2,3). So answer NO. So correct.
Now what about (11,12): x=11 prime, y=12=11+1 -> YES.
Now (13,14): yes.
Now (17,18): yes.
Now (19,20): yes.
Now (23,24): yes.
Now (29,30): yes.
Now (31,32): yes.
Now (37,38): yes.
Now (41,42): yes.
Now (43,44): yes.
Now (47,48): yes.
Now (53,54): yes.
Now (59,60): yes.
Now (61,62): yes.
Now (67,68): yes.
Now (71,72): yes.
Now (73,74): yes.
Now (79,80): yes.
Now (83,84): yes.
Now (89,90): yes.
Now (97,98): yes.
Now (101,102) but 102 > 100000? Actually 102 ≤ 100000? 102 ≤ 100000 yes. But x=101 prime; y=102. So that would be a valid test case possibly.
Now check up to 100000: primes up to 99991, so all fine.
Now think about possible other patterns: Could there be fielders at positions with x positive and y positive from moves that are not of the form 4k+2? For example, after move 1: (1,0) y=0 not positive. After move 5: (3,-2) y negative. After move 9: (5,-4) y negative. After move 13: (7,-6) y negative. After move 17: (9,-8) negative. After move 21? Let's compute: move 21: after move 20 at (-10,-10), move 21 east length 21 -> (11,-10) (y negative). So no. After move 22 north length 22 -> (11,12) (positive y). So indeed only every 4 moves after move 2.
Thus all good.
Now implement.
But wait: The problem says "the cricket ground to be an infinite grid and there can be more than 11 players in a team." That just indicates that there are many fielders, not just 11. So we have infinite fielders.
Thus solution.
Now there is a potential nuance: The "prime numbered positive positions of x" might be interpreted as "the positions of fielders that are numbered (the fielder numbers) that are prime and also the x coordinate is positive"? But we already argued sample disproves prime index. However, sample has (3,4) which is fielder 6, not prime. So no.
Another nuance: "prime numbered positive positions of x" might be interpreted as "positions where x is a positive integer that is prime-numbered", i.e., x is a prime number? That's what we used.
Thus we are confident.
Now we need to produce a solution that can handle up to 10^5 and T up to 100. Very straightforward.
But wait, is there any scenario where (x,y) is a fielder with x prime positive but y positive but not x+1? Could there be a fielder with both coordinates positive at a different point due to overlapping? For example, after many moves, could the spiral revisit a point? The spiral expands, so it may eventually overlap? But is it possible that the path goes through a point with both coordinates positive that is not of that form? For example, after move 6 we are at (3,4). After move 14 we are at (7,8). Could there be a move that lands on (5,4)? Let's see: (5,4) maybe from move? The path moves in straight lines of increasing length. It seems unlikely to land on a point not described. But we can mathematically prove that the only fielder positions are those four forms we derived. So there is no overlapping; each point is unique. The spiral is like a "square" shape with corners at (k, -k), (k, k), (-k, k), (-k, -k) for appropriate k? Actually observe: After moves:
After 4k+1: (2k+1, -2k) -> on bottom right corner? Actually that's on the line y = - (x-1), x positive.
After 4k+2: (2k+1, 2k+2) -> top right? But note y = x+1.
After 4k+3: (-(2k+2), 2k+2) -> top left.
After 4k+4: (-2k-2?, after 4(k+1)? Actually 4k+4: =4(k+1) so after move 4(k+1) we get (-2(k+1), -2(k+1))? Wait we had after move 4k (k>=1) we get (-2k, -2k). So after move 4(k+1) we get (-2(k+1), -2(k+1)). So that's bottom left.
Thus these are the four corners of a "square" but not exactly square because the east and west moves are of odd length? Actually the shape is like a rectangle? But anyway.
Thus only positive-positive points are from the 4k+2 moves, and they are exactly (odd, odd+1). So correct.
Now implement.
But careful: The problem says "Input starts with T denoting the number of test cases. Next T lines contains space separated coordinates x,y which are coordinates of point where Clarke has positioned himself." It doesn't explicitly say that x,y are integers? But obviously they are, because they are grid coordinates. And constraints say 1 ≤ x,y ≤ 10^5, so integers.
Now the output: Print "YES" or "NO".
Now we should consider the case x=2, y=3: Our condition would output NO, which we think is correct.
But is there any subtlety: Could (2,3) be a fielder if we consider that the batsman is at (0,0) and the fielders are placed at those positions. Could there be a fielder at (2,3) from a different move? Let's compute more moves: Move 14 gave (7,8). Move 18 gave (9,10). Move 22 gives (11,12). So no. Move 2 gave (1,2). So x=2 doesn't appear. So fine.
Now implement sieve. But we can also just test primality up to sqrt(x) for each test case, since T is only 100 and x up to 10^5, that's fine. But using sieve is efficient.
But need to be careful: prime[0] and prime[1] false.
Now final code:
code
def sieve(n):
prime = [True]*(n+1)
prime[0]=prime[1]=False
for i in range(2, int(n**0.5)+1):
if prime[i]:
for j in range(i*i, n+1, i):
prime[j]=False
return prime
Then:
code
prime = sieve(100000)
for _ in range(T):
x,y = map(int, input().split())
if y == x+1 and prime[x] and x != 2:
print("YES")
else:
print("NO")
But note: x=2 will have prime[2]=True but we exclude. Actually x=2 is prime but not a fielder, so NO. So we need to exclude x=2.
Alternatively, we could check if x%2==1 and prime[x]. That excludes 2 automatically. So:
x=2,y=3: x prime but even, y = 3, x+1=3, but x=2 is not odd, so according to our condition we need to ensure x is odd. Our condition x%2==1 will exclude it => NO. Good.
Thus final.
Now ensure we cover all cases.
But is there any fielder with x positive prime and y positive but not equal x+1? For example, could there be a fielder at (3,2)? That would be on the path? Let's see: from (1,2) moving west 3 lands at (-2,2), not (3,2). From (3,-2) moving north 6 goes to (3,4). So not (3,2). From (5,6) moving west 7 goes to (-2,6). No. So no.
Thus fine.
Now we could also derive more directly: For positive y, the point (x,y) is a fielder iff x and y are consecutive integers with x odd. But the catching condition adds that x is prime. So we can simplify even further: check if y == x+1, x is odd, and x is prime.
But note: x odd and prime automatically implies x is odd prime (i.e., >2). So we can just check if y == x+1 and isPrime(x) and x != 2.
Alright.
Now I'll write the solution accordingly.
But wait: The problem statement says "prime numbered positive positions of x on X-Y plane on the grid". Could it mean the x-coordinate is a prime number, and also the position is positive (i.e., both coordinates positive)? "positive positions of x" could be interpreted as "positions where x is positive". But they also say "on X-Y plane on the grid", maybe just clarifying. I think it's as we used.
Nevertheless, given sample, our interpretation matches.
Thus answer.
But before finalizing, I'll consider if there could be a fielder at (x,y) with x positive prime and y positive but not x+1 due to a different starting point? No.
Now implement.
But there is also the possibility that the problem expects to consider all fielders (including those with negative y) and the input includes negative y? But constraints say y ≥ 1, so no.
Thus solution stands.
Now I'll produce final answer.
But the problem might have a twist: "prime numbered positive positions of x" might be interpreted as "the x-coordinate is a prime number and also the position is in the positive quadrant (both coordinates positive)". That is, "positive positions" meaning both x and y positive. That would align with our selection: we are only considering positive coordinates anyway. So the catching positions might be those fielders in the first quadrant (x>0, y>0) with x prime. And we derived that those are exactly (p, p+1). So same.
Thus everything consistent.
Now code.
Complexity: O(N log log N) for sieve, then O(T) queries.
Now we need to ensure the sieve size is 100000 maybe plus 1.
Now final solution.
But before finishing, I'll test a few more inputs:
Input:
1
1 2
Output: NO (since x=1 not prime)
Input:
1
3 4
Output: YES
Input:
1
5 6
Output: YES
Input:
1
7 8
Output: YES
Input:
1
9 10
Output: NO
Input:
1
2 3
Output: NO
Input:
1
4 5
Output: NO
Matches.
Now also consider if x=1, y=0? Not allowed (y≥1). So not needed.
Now one more nuance: In our derivation, we assumed that the positions are exactly given by formulas for all moves. But the pattern says "1st fielder is to be placed at 1 step to the east of batsman. 2nd fielder is to be placed at 2 steps to the north of 1st fielder ... And so on… The fielders can be placed at only these positions and no where else…i.e at (1,0) , (1,2) , ( -2,2) , (-2,-2) and so on." So yes.
Thus answer is as we have.
Now I'll produce the final answer explanation.
But to be thorough, we might want to double-check if there is any alternative pattern: Could the fielders be placed not at the endpoint of each move, but at the location after each step? That is exactly what we used.
Now check the phrase: "1st fielder is to be placed at 1 step to the east of batsman." That means fielder 1 at (1,0). Then "2nd fielder is to be placed at 2 steps to the north of 1st fielder" means from fielder 1, go north 2 steps, place fielder 2 at (1,2). So correct.
Thus no confusion.
Now final answer: print YES if y == x+1 and x is prime (and x != 2? Actually prime includes 2, but x=2 not valid, but we can check x>2). Or if x is odd prime.
Thus final.
Now I'll code. ```python
import sys
def sieve(limit: int):
"""Return a boolean list where prime[i] is True if i is prime."""
prime = [True] * (limit + 1)
prime[0] = prime[1] = False
for p in range(2, int(limit ** 0.5) + 1):
if prime[p]:
for multiple in range(p * p, limit + 1, p):
prime[multiple] = False
return prime
def main():
data = sys.stdin.read().strip().split()
if not data:
return
t = int(data[0])
# maximum possible x is 1e5
MAX = 100000
is_prime = sieve(MAX)
out_lines = []
idx = 1
for _ in range(t):
x = int(data[idx]); y = int(data[idx+1])
idx += 2
# catching positions (with x>0,y>0) are exactly (p, p+1) where p is an odd prime
if y == x + 1 and x % 2 == 1 and is_prime[x]:
out_lines.append("YES")
else:
out_lines.append("NO")
sys.stdout.write("\n".join(out_lines))