#K67542. Perfect Chocolate Bar Fitting
Perfect Chocolate Bar Fitting
Perfect Chocolate Bar Fitting
You are given a chocolate bar with dimensions \(a \times b\) and several package boxes. Your task is to determine whether at least one of the boxes can perfectly hold an integral number of chocolate bars without leaving any empty space.
A box of dimensions \(W \times H\) can perfectly contain the chocolate bars if one of the following conditions is satisfied:
- \(W \mod a = 0\) and \(H \mod b = 0\), or
- \(W \mod b = 0\) and \(H \mod a = 0\) (i.e. the bar is rotated 90°)
For each test case, check the available boxes and output yes
if there exists at least one box that meets the conditions, otherwise output no
.
inputFormat
The input is given via standard input (stdin) and consists of multiple test cases.
The first line contains an integer \(T\) denoting the number of test cases.
For each test case:
- The first line contains three integers: \(a\), \(b\), and \(n\) where \(a\) and \(b\) represent the width and height of the chocolate bar, and \(n\) is the number of available boxes.
- Each of the following \(n\) lines contains two integers \(W\) and \(H\), the width and height of a box.
outputFormat
For each test case, output a single line containing either yes
or no
.
Output yes
if there exists at least one box that can perfectly hold one or more chocolate bars according to the above conditions; otherwise, output no
.
2
4 5 2
8 10
9 9
6 7 1
14 14
yes
no
</p>