Skip to content

2176. Count Equal and Divisible Pairs in an Array #1570

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to count the number of pairs (i, j) in a given array such that the elements at these indices are equal and the product of their indices is divisible by a given integer k.

Approach

The approach involves iterating through all possible pairs of indices (i, j) where i < j. For each pair, we check two conditions:

  1. The elements at indices i and j are equal.
  2. The product of i and j is divisible by k.

Given the constraints that the array length is at most 100, a brute-force approach is feasible. This approach involves checking each pair directly, which is manageable due to the small size of the input.

Let's implement this solution in PHP: 2176. Count Equal and Divisible Pairs in an Array

<…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@topugit
Comment options

topugit Apr 17, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Apr 17, 2025
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested easy Difficulty
2 participants