Limits 2s, 128 MB

Sheldon and Leonard are roommates. Usually Leonard drives Sheldon to work everyday as Sheldon can’t drive and hates bus. For some reason, Leonard has gone to his home for indefinitely. So, Sheldon asks Penny who lives across the hall to drive him to work. As we all know Sheldon is and annoying person to be with and Penny hates to get up at 7am! So, they signed a contract which states the following-

Sheldon gives Penny two integers PP and DD. Sheldon wants to know if there are two positive integers XX and YY such that difference between PP and XYX*Y is exactly DD and GCDGCD(greatest common divisor) between XX and YY must be DD. i.e. PXY=D|P-X*Y|=D and gcd(X,Y)=Dgcd(X,Y)=D.

The problem will be given to Penny every night. If she gives the correct answer, Sheldon will take the bus next morning. Otherwise she will have to get up early and she doesn’t want ruin her precious sleep. So, she hires you to write a program which will give correct answer to the above problem.


The first line contains an integer T(1T105)T(1 \leq T \leq 10^5)-the number of tests.

The following TT lines describe the tests.

Each test contains two positive integers P(1P1018)P(1 \leq P \leq 10^{18}) and D(1D<P)D(1 \leq D<P).


For each test case, in single line print NoNo if there are no such XX and YY which fulfill Sheldon’s conditions else print YesYes.


20 4
23 5


Login to submit.


53% Solution Ratio
FAHIM.ctgEarliest, Nov '22
insane_curiousFastest, 0.0s
nusuBotLightest, 4.9 MB
efat1531Shortest, 380B
Toph uses cookies. By continuing you agree to our Cookie Policy.