PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000148. Kiểm tra đoạn có tổng chia hết (Continuous Subarray Sum)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Kiểm tra đoạn có tổng chia hết (Continuous Subarray Sum)
Continuous Subarray Sum
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given an array of nonnegative integers and a positive integer , determine whether there is a contiguous interval of at least two elements whose sum is a multiple of . A sum of zero is also a multiple of .
Input
- Line 1: two integers , the array length and the divisor.
- Line 2: integers in order.
Output
Print true if such an interval exists, otherwise false (lowercase).
Subtasks
- Subtask 1 (20 points): ; for every ; ; .
- Subtask 2 (30 points): ; for every ; ; .
- Subtask 3 (50 points): ; for every ; ; .
Example 1
Input
5 6
23 2 4 6 7
Output
true
Explanation
Positions 2 through 3 contain 2 and 4, have length 2, and sum to 6.
Example 2
Input
5 6
23 2 6 4 7
Output
true
Explanation
The entire array has sum 42, equal to , and length 5.
Example 3
Input
5 13
23 2 6 4 7
Output
false
Explanation
The sums of intervals of length at least 2 are 25, 31, 35, 42, 8, 12, 19, 10, 17, 11. None is a multiple of 13.