Problem Description
Loading...
Problem Analysis
Chinese statement:
Given a sequence, determine whether there exists a contiguous subarray whose sum is a multiple of m. Output YES if it exists, otherwise output NO.
Official solution:
Precompute the prefix sums. As soon as two prefix sums are congruent modulo m, the segment between them forms a contiguous subarray whose sum is a multiple of m. In addition, by the pigeonhole principle, once n is greater than or equal to m, the answer is always YES. Complexity O(n).
cpp
| |