Does Mathematica have a function for the composite numbers not divisible by a squared prime?

206 Views Asked by At

I'm looking for a formula in Mathematica that gives me the sequence of integers whose prime decomposition is p1*p2*...*pn, that is, not divisible by any squared prime. Does it even exist?

2

There are 2 best solutions below

3
On

No, it doesn't, but you can easily make your own using just built-in functions.

Select[Complement[Range[100], Prime[Range[PrimePi[100]]]], MoebiusMu[#] != 0 &]

Not the most elegant, and perhaps not too adaptable to your purpose, but I hope it points you in the right direction.

1
On

Wolfram Mathematica does have a built-in function that tells you if a number is prime, and it has a built-in function that tells you if a number is squarefree, but it doesn't have a built-in function that tells you if a number is composite and squarefree.

But you can very easily make your own. Here's one way out of many:

sqrFreeCompQ[n_] := (SquareFreeQ[n] && (PrimeNu[n] > 1));

(the difference between PrimeNu and PrimeOmega is irrelevant for this particular use)

I haven't tested this because my license server is acting funny today.


Just for a lark, I put the following into Wolfram Alpha:

Sum[(1/n)Boole[SquareFreeQ[n] && (PrimeNu[n] > 1)], {n, Infinity}]

Wolfram Alpha says that "by the harmonic series test, the series diverges." Then I tried changing Infinity to 1000, it gives roughly $2.044313$ for the answer. But then I reread your comment so then I tried

Sum[(1/n^2)Boole[SquareFreeQ[n] && (PrimeNu[n] > 1)], {n, Infinity}]

but this is too much for Wolfram Alpha. Hopefully the technician fixes my license server tomorrow...