Mathison and the divisible trios
Practice
3.3 (27 votes)
Easy
Hash tables
Math
Problem
79% Success 5321 Attempts 30 Points 0.6s Time Limit 256MB Memory 1024 KB Max Code

Mathison has discovered an old piece of paper with N integers written on it. Let's call this given sequence of numbers A. In his History class, Mathison has learnt that a trio of numbers is special if and only if their sum is divisible by a mythical constant M.

Mathison tries to find out how many distinct triplets of numbers, from the piece of paper, have their sum divisible by M. Unfortunately, this problem is quite hard to crack and he needs your help.

Input
The first line of the input file contains two space-separated integers, N and M, representing the number of integers and the mythical constant.
The next line contains N space-separated integers, where the \(i^{th}\) integer represents \(A[i]\).

Output
The output file should contain only one integer, the answer to Mathison's question.

Constraints

  • \( 1 \le N \le 2 \times 10^5 \)
  • \( 1 \le M \le 10^4 \)
  • \( 0 \le A[i] \le 2 \times 10^9 \)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
20 votes
Tags:
Data StructuresEasyHash Tables
Points:30
118 votes
Tags:
EasyHash MapsHashing algorithmString Manipulation