Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Get the number of all possible combinations that give a certain product

$
0
0

I'm looking for a algorithm that counts number of all possible combinations that gives certain product.I have a list of perfect squares[1,4,9,16,..,n]and I have two values a, b where a - number of elements that we can use in multiplication to get perfect square, b - maximum value of each element that can be used in multiplicationFor example, if a = 3 and b = 6 then for perfect square 36 we can have combinations such as [1,6,6], [2,3,6], [4,3,3] and so on. NOTE we can not use [1,9,4] combination because 9 > b

I've tried to use combinations of all divisors for each perfect square from itertools and after that I checked each product of combination and if x1x2x3 == 36 I added 1 to my counting. This algorithm works but it requires significant amount of time for long multiplication.

Can we make it faster than look at each combination for each perfect square?


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>