colors[i] is the color of bead i. You are also given a number divisor.
Count the pairs of positions (i, j) with i < j where both beads have the same color (colors[i] == colors[j]) and the product i * j is divisible by divisor.colors=[4, 2, 4, 2, 4], divisor=3 → 3
Equal pairs are (0, 2), (0, 4), (2, 4) for color 4 and (1, 3) for color 2. Their products are 0, 0, 8 and 3, and 0, 0 and 3 are divisible by 3. The answer is 3.
colors=[1, 2, 3], divisor=1 → 0
No two colors match, so there are no pairs.
colors=[7, 7], divisor=5 → 1
The only pair is (0, 1): 0 · 1 = 0, and zero is divisible by anything.
divisor ≤ 100colors=[4, 2, 4, 2, 4], divisor=3
3
Run checks the first 3 tests in your browser. Submit checks all 90 tests on the server, hidden ones included.