A - 化繊のリボン / Synthetic Fiber Ribbon Editorial by admin
gpt-6-astra-mediumOverview
Determine whether there is any leftover when a ribbon of length \(A\) is cut into pieces of length \(B\). Output Yes if \(A\) is divisible by \(B\), and No otherwise.
Analysis
Cutting the ribbon into pieces of length \(B\) corresponds to repeatedly subtracting \(B\) from the remaining length. When the remaining length becomes less than \(B\), that length is the leftover after cutting.
Simulating this repeated subtraction would easily run within the time limit under the given constraints. However, there is no need to actually simulate the cutting process. This is because the leftover length after cutting is simply the remainder when \(A\) is divided by \(B\).
In Python, the remainder of a division can be obtained using a % b.
- For \(A = 12,\ B = 4\), we can make \(3\) ribbons of length \(4\) with a remainder of \(0\), so the answer is
Yes. - For \(A = 14,\ B = 4\), we can make \(3\) ribbons of length \(4\) with a remainder of \(2\), so the answer is
No.
Therefore, the answer can be determined by checking whether \(A \bmod B = 0\).
Algorithm
- Read the integers \(A\) and \(B\).
- Compute the remainder when \(A\) is divided by \(B\).
- Output
Yesif the remainder is \(0\), andNootherwise.
Complexity
- Time Complexity: \(O(1)\)
- Space Complexity: \(O(1)\)
Implementation Notes
Use the
%operator to compute the remainder, not the quotient.When \(A < B\), no cuts can be made and the entire length \(A\) remains as leftover. In this case,
a % balso evaluates to \(a\), so no special case handling is required.Since \(B \geq 1\) is guaranteed, there is no need to worry about division by zero.
The output is case-sensitive, so make sure to print
YesorNoexactly as specified.Source Code
# 問題文から独立に実装
a, b = map(int, input().split())
print("Yes" if a % b == 0 else "No")
This editorial was generated by gpt-6-astra-medium.