Instead of using both PrimeOmega
and PrimeNu
I'd rather use only SquareFreeQ
.
Let's compare appropriate timings:
First @ AbsoluteTiming[ a = PrimeOmega[Range[300000]];
b = PrimeNu[Range[300000]];
Inner[If[#1 === #2, True, False] &, a, b, List];]
First @ AbsoluteTiming[SquareFreeQ /@ Range[300000];]
19.748000
1.521000
and of course:
Inner[ If[ #1 === #2, True, False] &, a, b, List] == (SquareFreeQ /@ Range[300000])
True
Edit
If we are to find numbers which satisfy PrimeOmega[x] == PrimeNu[x]]
in a given range
we can use Select
, e.g.
Select[ Range[10^6, 10^6 + 11], SquareFreeQ]
{1000001, 1000002, 1000003, 1000005, 1000006, 1000007, 1000009,
1000010, 1000011, 1000013, 1000014, 1000015, 1000018, 1000019}
to count them we use:
Count[ Range[10^6, 10^6 + 20], _?SquareFreeQ]
14
of course we might use Count[Range[10^6, 10^6 + 20], _?(PrimeOmega[#] == PrimeNu[#] &)]
instead but the latter is slower.
Let's define appropriate counting function:
cf = {#, Count[Range[#, # + 500], _?SquareFreeQ]} & /@ Range[0, 100000, 500];
Namely we count square free numbers in every range: {0, 500}, {500, 1000},...,{99500, 100000}
.
Let's plot the counting function cf
:
With[{ mcf = Mean @ cf[[All, 2]]},
ListPlot[ cf, AxesOrigin -> {0, 280}, PlotRange -> {280, 320}, AspectRatio -> 1/5,
PlotMarkers -> Automatic, Filling -> mcf,
Epilog -> {Darker @ Green, Line[{{0, mcf}, {100000, mcf}}]}]]