Official
A - 化繊のリボン / Synthetic Fiber Ribbon Editorial by admin
swe-2-highExplanation
Takahashi cuts a ribbon of length \(A\) centimeters into pieces of \(B\) centimeters, starting from the left end. He can make \(\lfloor A / B \rfloor\) ribbons of length \(B\), and the leftover part after cutting has length \(A \bmod B\) centimeters.
No remainder is left exactly when \(A \bmod B = 0\), i.e., when \(A\) is divisible by \(B\). Therefore the check is simply:
- If \(A \bmod B = 0\), print
Yes. - Otherwise, print
No.
Proof of Correctness
By the division algorithm, \(A\) can be uniquely written as \(A = qB + r\) with \(0 \le r < B\), where \(q = \lfloor A/B \rfloor\) and \(r = A \bmod B\).
- If \(r = 0\), then \(A = qB\), so after exactly \(q\) cuts the ribbon is used up completely and no remainder remains. Thus
Yesis correct. - If \(r \ge 1\), then after \(q\) cuts a piece of length \(r\) (with \(1 \le r < B\)) remains, which is shorter than \(B\) centimeters. Thus
Nois correct.
Hence checking whether \(A \bmod B = 0\) yields the correct answer.
Complexity
- Time: \(O(1)\)
- Space: \(O(1)\) (only two integers are read as input)