#C2173. Path Product Divisibility
Path Product Divisibility
Path Product Divisibility
Given two integers (N) and (M), determine whether there exists a path from cell ((N,1)) to cell ((1,N)) in a grid such that the product of all the numbers on the path is divisible by (M).
The grid is implicitly defined by the natural numbers from 1 to (N) and the path selection is based on divisibility properties. In particular, for each prime factor (p) of (M) with exponent (e), the maximum number of times (p) can appear on the path is (2\lfloor \frac{N}{p} \rfloor - 1). If for any prime factor this value is less than (e), then the answer is "No"; otherwise, it is "Yes".
Note: When (M = 1), any product is divisible by 1.
inputFormat
The input is read from standard input (stdin).
The first line contains an integer (T), the number of test cases. Each of the following (T) lines contains two space-separated integers (N) and (M).
outputFormat
For each test case, output a single line containing "Yes" if there exists a valid path from ((N,1)) to ((1,N)) such that the product of the numbers on the path is divisible by (M); otherwise, output "No".## sample
3
2 2
3 3
3 4
Yes
Yes
No
</p>