Mathematica: How do I program this? Square free part of an integer

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
3 replies · 3K views
ABarrios
Messages
23
Reaction score
0
I am attempting to program Mathematica to multiply the square free terms of an integer. Basically say we are looking at 252, its prime factors are 2^2*3^2*7. So what I want to do is have Mathematica return to me just 2*3*7 when I enter 252.

So I have this

S := FactorInteger[252]
Transpose[[1]]

which returns

{{2, 2}, {3, 2}, {7, 1}}
{2, 3, 7}

So, knowing a way to have Mathematica multiply 2*3*7 will give me what I need. Thanks!
 
Physics news on Phys.org
Times @@ {a, b, c, d, ...} I think is the clever way to do it. I'm pretty sure there is a Product function you could make use of, and in a pinch, you could always write a Function or Module yourself that uses Do to create a loop.
 
Use the Apply operator, @@. Times@@{a,b,c} will return the product of a, b, and c.
 
Thank you very much!