A - 化繊のリボン / Synthetic Fiber Ribbon Editorial by admin Editorial for printing
gpt-6-astra-mediumOverview
Determine whether there will be any leftover ribbon when a ribbon of length \(A\) is cut into pieces of length \(B\). If \(A\) is divisible by \(B\), output Yes; otherwise, output No.
Analysis
If we make as many ribbons of length \(B\) as possible, the length of the remaining part will be the remainder of \(A\) divided by \(B\).
For example, we can consider the following cases:
- When \(A=12,\ B=3\), we can make \(4\) ribbons of length \(3\) with a remainder of \(0\). Therefore, the answer is
Yes. - When \(A=14,\ B=3\), making \(4\) ribbons of length \(3\) leaves a remainder of length \(2\). Therefore, the answer is
No.
Repeatedly subtracting \(B\) from \(A\) would also easily pass within the given constraints. However, there is no need to simulate the cutting process; we can determine the result in a single operation using the modulo operator %.
That is, the condition for having no leftover ribbon is \(A \bmod B = 0\).
Algorithm
- Read the integers \(A\) and \(B\).
- Compute the remainder of \(A\) divided by \(B\) using
A % B. - If the remainder is \(0\), output
Yes; otherwise, outputNo.
Complexity
- Time Complexity: \(O(1)\)
- Space Complexity: \(O(1)\)
Implementation Notes
In Python, you can check whether “\(A\) is divisible by \(B\)” using
A % B == 0.If \(A < B\), no ribbons can be made, and the entire ribbon of length \(A\) remains as leftover. In this case as well,
A % Bevaluates to \(A\), which correctly yieldsNo.By the constraints, \(B \geq 1\), so there is no concern about division by zero.
The output is case-sensitive, so make sure to output
YesorNoexactly as specified.Source Code
def main():
import sys
A, B = map(int, sys.stdin.readline().split())
print("Yes" if A % B == 0 else "No")
main()
This editorial was generated by gpt-6-astra-medium.
posted:
last update: