# Find square numbers in product

If I have the product of some unique numbers such as:

$9 . 6 . 8 . 10 = 4320$

(edit where each of the products must be less than or equal to a given number, 10)

If I want to find if any of the numbers is a square I would decompose as follows:

$(3\,.\,3)\,.\,(3\,.\,2)\,.\,(4\,.\,2)\,.\,(5\,\,.\,2) = 4320$

here obviously 9 is the square number but is there a function to do that in Mathematica 9?

The nearest I have found finds powers of unique primes:

$2^5 . 3^3 . 5 = 4320$

using the function:

FactorInteger
{{2, 5}, {3, 3}, {5, 1}}


Is there any general way to find if a number such as 4320 contains any square numbers in products such as 9 such that this is less than or equal to 10 and is still a product of 4 numbers in this case?

• Does SquareFreeQ work for you? – Carl Woll Jun 17 '18 at 13:40
• There are more squares in $4320$ beyond $9$: you also have $4=2^2$, $16=4^2$. Do you want a list of all primes squared, or also non-primes? – AccidentalFourierTransform Jun 17 '18 at 13:44
• SquareFreeQ pulls all the squares I need just the squares present in the 4 unique numbers that make the product and yes I mean prime squares only. – onepound Jun 17 '18 at 13:47
• First[#]^2 & /@ Select[FactorInteger, #[] > 1 &] ? – AccidentalFourierTransform Jun 17 '18 at 13:51
• How about PrimePowerQ? – Carl Woll Jun 17 '18 at 13:53

I have had an idea based on @AccidentalFourierTransform comment.

First[#]^2 & /@ Select[FactorInteger, #[] > 1 &]


produces two squares in the case of 4320 '4' and '9' but only one will reconstruct 4320 with just 4 numbers less than or equal to 10.

4 would fail since since 4 is less than half of 10 therefore all squares less than 5 can be excluded since 10.9.8.4 < 4320.

Select[First[#]^2 & /@ Select[FactorInteger, #[] > 1 &], 5<= # <= 10 &]


and generalised replacing constants shown as convenient:

Select[First[#]^2 & /@ Select[FactorInteger[m], #[] > 1 &], (n/2) <= # <= n &]