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 NN integers. Count the number of pairs whose sum is divisible by 55 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)(2, 1) and (1,2)(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)(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)(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(1t100)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(1N103)N (1\leq N\leq10^3) — the size of
the array. The second line contains NN integers A1,A2,,An(1Ai109)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, XX is the test case number starting from 11 and YY is the number of pairs whose sum is divisible by 55 in the given array).


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



    98% Solution Ratio

    steinumEarliest, Oct '20

    steinumFastest, 0.0s

    ishaan_007Lightest, 0 B

    mdvirusShortest, 270B


    Login to submit

    Toph uses cookies. By continuing you agree to our Cookie Policy.