Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Same Product
Given an array of distinct positive integers, return the number of tuples (a, b, c, d) such that a * b = c * d where a, b, c, and d are elements of the array, and a != b != c != d.
Input Format:
First line of input contains an integer N, representing the number of elements in array
Second line of input contains N space separated integers
Output Format:
Print the required count
Sample Input 1:
4
2 3 4 6
Sample Output 1:
8
Explanation:
There are 8 valid tuples:
(2,6,3,4) , (2,6,4,3) , (6,2,3,4) , (6,2,4,3)
(3,4,2,6) , (4,3,2,6) , (3,4,6,2) , (4,3,6,2)


What I have tried:

I didn't understand how to approach
Posted
Updated 4-Jan-23 20:10pm
Comments
Graeme_Grant 5-Jan-23 0:29am    
This is a homework question. It is based on what you learned in your class. We are not here to do your homework for you.
Atul Gupta 2023 5-Jan-23 2:01am    
I am not asking the whole solution

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

Working out how to solve a problem is a very important part of the exercise - it builds skill which looking at a solution from someone else doesn't because that does not show you why other solutions were rejected.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
Break it down...

** A cannot = B cannot = C cannot = D => all numbers are unique!
** but you want the product A * B = C * D

There are examples:
2 * 6 = 3 * 4 -> 12 = 12

Your code should return sets like those... ie: the answers are there, you just need to write the code to generate them.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900