PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000226. Đếm cặp có tổng và hiệu chia hết (Divisible Pairs)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm cặp có tổng và hiệu chia hết (Divisible Pairs)
Divisible Pairs
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given an array and positive integers , count index pairs satisfying both and . Divisibility is defined for integers, including negative differences. Count each pair once.
Input
First line contains ; second line has integers .
Output
Print the number of valid index pairs.
Subtasks
-
Subtask 1 (20 points): .
-
Subtask 2 (30 points): .
-
Subtask 3 (50 points): .
Examples
Example 1
Input
6 5 2
1 2 7 4 9 6
Output
2
Explanation
The valid index pairs are (1,5), with sum 10 and difference -8, and (4,6), with sum 10 and difference -2.
Example 2
Input
3 1 1
2 2 2
Output
3
Explanation
Every pair of distinct indices qualifies: .