Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am trying to generate a list of cubefree numbers (i.e. numbers when prime factorized contain no tripled factors) within a given range.

Of DivisorSigma, PrimeOmega, Divisors, PrimeNu and FactorInteger, FactorInteger seems to me to be the best suited to the task (please feel free to suggest more suitable methods). For example,

FactorInteger[630]

outputs

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

From this, I would like Mathematica to focus on the second number in each pair (the exponent) and determine which has the highest value. In this case, it is {3,2}, indicating that 630 is a cubefree number (i.e. - having no prime factor with a greater exponent than 2).

Is it possible to do this with a range of numbers, so that Mathematica evaluates each number in this way within a range, and then outputs that list of numbers?

share|improve this question
add comment

3 Answers

up vote 4 down vote accepted
SetAttributes[cubeFreeQ, Listable]

cubeFreeQ[n_Integer] := Max@FactorInteger[n][[All, 2]] < 3

seems straightforward

To find all the cube-free numbers in the first 1000 integers, do

Select[Range[1000], cubeFreeQ]
share|improve this answer
    
many thanks for this. Is there any way to output a list of these - ie, to keep the numbers whose cubefree value is 'True' and delete thos from thelist that are 'False', and vice versa? –  martin Nov 19 '13 at 11:44
1  
@martin see edit –  Aky Nov 19 '13 at 11:47
    
@ Aky - fantastic! - thanks :) –  martin Nov 19 '13 at 11:47
add comment
FreeQ[ Last @ Transpose @ FactorInteger[630], 3]
True

In general:

cubeFreeQ[n_Integer] := FreeQ[ Last @ Transpose @ FactorInteger[n], _?(# >= 3 &)]

It works like this:

cubeFreeQ /@ {113, 125, 137, 256, 193839272}
{True, False, True, False, False}

And you can select cube free numbers this way:

Cases[{15, 16, 24, 36, 48, 77, 125, 12094709274}, _?cubeFreeQ]
{15, 36, 77, 12094709274}
share|improve this answer
    
cubefreeQ[64] yields True yet 64 =4^3 –  ubpdqn Nov 19 '13 at 11:10
    
@ubpdqn No it yields False. –  Artes Nov 19 '13 at 11:12
    
My comment related to your general answer that did not have the inequality not the subsequent edit...no offence intended –  ubpdqn Nov 19 '13 at 11:14
    
@Artes i tried my own implementation and realised later that your answer is more accurate, since you even factor out the exponent (e.g. 256 which is 2^8 and 8=2^3 therefore false) to find out, if it is cube free. very decent indeed. +1 –  Stefan Nov 19 '13 at 11:27
    
@Stefan Thanks, I guess you mean $256 = 2^3 \cdot 32 = 4 \cdot 4^3$ etc. Another way would play with divisors, but the latter seems to be more involved. –  Artes Nov 19 '13 at 11:36
show 2 more comments
cf[u_]:= And @@ ( # < 3 & /@ FactorInteger[u][[All,2]])

yields True for cf[630] while cf[64] yields False.

share|improve this answer
    
@ Ubpdqn, Thanks for this. Is there any way to output a list of these - ie, to keep the numbers whose cubefree value is 'True' and delete thos from thelist that are 'False', and vice versa? –  martin Nov 19 '13 at 11:45
    
Select[list,cf] is one way but as you know in Mathematica there is more than one way to do things, e.g Cases, Pick etc. Setting attribute to Listable, as per Aky, would let you apply to list and then use Pick. –  ubpdqn Nov 19 '13 at 11:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.