All submissions for this problem are available.
A and B are brothers and like playing with marbles.Their mother buys them N marbles to play with.The preciousness of each marble is a natural number from 1 to N and no two marbles have same preciousness.
Since A and B are good at maths they want to divide all those N marbles among them in such a way that sum of the preciousness of all marbles that A receives and sum of the preciousness of all marbles that B receives after distribution are co-primes i.e the gcd(greatest common divisor) of their sum is 1.
Also the absolute value of difference between the sum of the preciousness of marbles of A and B should be exactly M.
Help A and B in finding whether such a distribution of N marbles between them is possible or not.
Formally, you have to tell whether you can distribute first N natural numbers in two sets such that the absolute difference of the sum of numbers in the two sets is equal to M and the gcd of their sum is 1.
Note that one of the set can be empty and greatest common divisor of 0 and k is k
- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
- The first line of each test case contains two integers N and M denoting the number of marbles and the absolute difference of sum respectively.
- For each test case, output a single line.
Print “Yes” if there exist a valid distribution of marbles between A and B else print “No”.
- 1 ≤ T ≤ 20
- 1 ≤ N ≤ 1,000,000,000
- 0 ≤ M ≤ 1018
Input: 2 5 7 1 2 Output: Yes No
|Tags||ad-hoc, gvaibhav21, inso2018, insomnia18, maths|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, CLOJ, COB, FS|
Fetching successful submissions