Given a number . The task is to count pairs (x, y) such that x*y is divisible by (x+y) and the condition 1 <= x < y < N holds true.
Input : N = 6 Output : 1 Explanation: The only pair is (3, 6) which satisfies all of the given condition, 3<6 and 18%9=0. Input : N = 15 Output : 4
The basic approach is to iterate using two loops carefully maintaining the given condition 1 <= x < y < N and generate all possible valid pairs and count such pairs for which the product of their values is divisible by sum.
Below is the implementation of the above approach:
Time Complexity : O(N2)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count the number of pairs (i, j) such that either arr[i] is divisible by arr[j] or arr[j] is divisible by arr[i]
- Count pairs from 1 to N such that their Sum is divisible by their XOR
- Count of pairs from 1 to a and 1 to b whose sum is divisible by N
- Count pairs (i,j) such that (i+j) is divisible by A and B both
- Print k numbers where all pairs are divisible by m
- Count sub-arrays whose product is divisible by k
- Count pairs in array whose sum is divisible by K
- Check if product of first N natural numbers is divisible by their sum
- Sum and Product of all Composite numbers which are divisible by k in an array
- Number of pairs from the first N natural numbers whose sum is divisible by K
- Count number of pairs in array having sum divisible by K | SET 2
- Count ordered pairs with product less than N
- Count of pairs of Array elements which are divisible by K when concatenated
- Count number of ordered pairs with Even and Odd Product
- Count unordered pairs (i,j) such that product of a[i] and a[j] is power of two
- Count all distinct pairs with product equal to K
- Count of pairs upto N such whose LCM is not equal to their product for Q queries
- Count of pairs in an array whose product is a perfect square
- Count of N-digit Numbers having Sum of even and odd positioned digits divisible by given numbers
- Count of pairs in an array such that the highest power of 2 that divides their product is 1
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.