PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000011. Đoạn con chia hết (Subarray Divisibility)
HỌC THEO LỘ TRÌNH
3 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đoạn con chia hết (Subarray Divisibility)
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
Given an array of integers, count the nonempty contiguous intervals whose sum is a multiple of . Two intervals with different endpoints count separately.
Input
The first line contains . The second line contains integers .
Output
Print the number of intervals whose sum is divisible by .
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
5
3 1 2 7 4
Output
1
Explanation
The interval contains , which sum to . To see why it is the only one, take the prefix sums including the empty prefix and reduce them modulo . The remainders are . Only the remainder occurs twice, at prefix lengths and , giving the interval .