Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Counting Pairs

By shojib_mu · Limits 2s, 512 MB

You are given an array of $N$ integers. Count the number of pairs whose sum is divisible by $5$ in the given array.

While repeating pairs will not be counted again. And we can’t make a pair using the elements which are in the same position. e.g.: $(2, 1)$ and $(1, 2)$ will be considered as only one pair. For better understand, you can look at the following example.

If we have an array of five integers — $(5, 5, 5, 5, 5)$, then the valid pairs according to their position in the array are $(1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (4, 5)$.


The first line contains an integer $t(1\leq t\leq100)$ — the number of sets of input data in the test. Input data sets must be processed independently, one after another.

Each input data set consists of two lines. The first line contains an integer $N (1\leq N\leq10^3)$ — the size of the array. The second line contains $N$ integers $A_1, A_2,…,A_n (1\leq A_i\leq 10^9)$.


For each input, print the output in the format, ‘Case X: Y’ (here, $X$ is the test case number starting from $1$ and $Y$ is the number of pairs whose sum is divisible by $5$ in the given array).


5 5 5 5 5
1 2 3 4 5
Case 1: 10
Case 2: 2



    97% Solution Ratio

    steinumEarliest, 2w ago

    steinumFastest, 0.0s

    ishaan_007Lightest, 0 B

    mdvirusShortest, 270B


    Login to submit