Close
Topic list
Pair Product Div by K
MEDIUM
35 mins
Other topics
Problem solved
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

# Pair Product Div by K

Contributed by
Jaypal Mudaliyar
Medium
0/80
Avg time to solve 35 mins
Success Rate 65 %
Share

## Problem Statement

#### 1 <= ‘i’ < ‘j’ <= ‘N’ and ‘nums[i] * nums[j]’ is divisible by ‘K’.

##### EXAMPLE :
``````‘N’ = 5, ‘K’ = 4, ‘nums’ = [2, 6, 1, 7, 8]
Output: 5
Explanation: (1, 2), (1, 5), (2, 5), (3, 5), and (4, 5) pairs have their products divisible by K.
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1 :
``````2
4 5
1 2 3 4
5 2
1 2 3 4 5
``````
##### Sample Output 1 :
``````0
7
``````
##### Explanation Of Sample Input 1 :
``````For the first test case, there is no pair of indices whose corresponding product is divisible by 5.

For the second test case, the seven pairs of indices whose corresponding products are divisible by two are
(1, 2), (1, 4), (2, 3), (2, 4), (2, 5), (3, 4), and (4, 5).
Their products are 2, 4, 6, 8, 10, 12, and 20 respectively.
Other pairs such as (1, 3) and (3, 5) have products 3 and 15, respectively, which are not divisible by 2.
``````
##### Sample Input 2 :
``````2
7 3
3 2 6 1 8 4 1
9 6
8 10 2 5 9 6 3 8 2
``````
##### Sample Output 2 :
``````11
18
``````
Auto
Console