# List of squareful, cubeful, etc. numbers

The following works:

list = {6, 7, 8, 9};
FreeQ2[n_Integer] := FreeQ[Last@Transpose@FactorInteger[n], _?(# >= 2 &)]
FreeQ3[n_Integer] := FreeQ[Last@Transpose@FactorInteger[n], _?(# >= 3 &)]
FreeQ4[n_Integer] := FreeQ[Last@Transpose@FactorInteger[n], _?(# >= 4 &)]
a = FreeQ2 /@ list /. {True -> 1, False -> 0};
b = FreeQ3 /@ list /. {True -> 2, False -> 0};
c = FreeQ4 /@ list /. {True -> 3, False -> 0};
Transpose[{a, b, c}] /. {{1, 2, 3} -> 1, {0, 2, 3} -> 2, {0, 0, 3} -> 3}


but of course is very inefficient coding. I was wondering what approach I should really be taking here.

-

I wanted a way without factorizing the numbers, but found none. So:

list = {6, 7, 8, 9};
Max /@ FactorInteger[list][[All, All, 2]]

(*
{1,1,3,2}
*)


Let's check the timings in my old laptop:

list = RandomInteger[10^6, 10^6];
Max /@ FactorInteger[list][[All, All, 2]] // Timing // First
(*
7 secs
*)

-
@ belisarius, this solution seems most straightforward to me - many thanks for your time :) – martin Nov 27 '13 at 10:46

Mathematica essentially has FreeQ2 built in:

FreeQ2[n_Integer] := MoebiusMu[n] != 0


Here's an idea for the rest. This depends on factoring an integer, but maybe something like

FreeQPow[n_, e_] := Head[n^(1/e)] === Power

-
Mathematica already has a built-in SquareFreeQ[n] – Dr. belisarius Nov 27 '13 at 2:11
@ RiemannZeta, thanks for your help on this - the bottom power solution is a nice start for me :) – martin Nov 27 '13 at 10:56

pwrs = Flatten[Max /@ DeleteDuplicates@Last@Transpose@FactorInteger[#] & /@ list,1];

Great - thanks for your help on this - I was trying to work out how to stack the transpose commands :) – martin Nov 27 '13 at 10:49