Greatest prime dividing the n-th cubefree number: Difference between revisions

→‎resursive alternative: changed to search for count of cubefree numbers
(→‎Version 2: Added a note and changes needed to use a BitArray for the sieve.)
(→‎resursive alternative: changed to search for count of cubefree numbers)
Line 553:
</pre>
===resursive alternative===
only counting til limit.Using Apéry's Constant, which is a quite good estimate.<br>Only checking powers of 10.Not willing to test prime factors > 6,98e12-> 0
<syntaxhighlight lang="pascal">
program CubeFree3;
Line 568:
const
//Apéry's Constant
Z3 = 1.20205690315959428539973816151144999;
RezZ3 = 0.831907372580707468683126278821530734417;
{
Line 580:
tPrimes = array[tPrimeIdx] of Uint32;
tDl3 = UInt64;
tDelCubetPrmCubed = array[tPrimeIdx] of tDl3;
var
{$ALIGN 8}
SmallPrimes: tPrimes;
DelCubePrmCubed : tDelCubetPrmCubed;
 
procedure InitSmallPrimes;
Line 629:
end;
 
procedure InitDelCubeInitPrmCubed(var DC:tDelCubetPrmCubed);
var
i,q : Uint64;
Line 664:
dec(j,4);
end;
end;
end;
 
function highestDiv(n: uint64):Uint64;
//can test til 2642246^2 ~ 6,98E12
var
pr : Uint64;
i : integer;
begin
CntDivsresult := 0n;
for i in tPrimeIdx do
begin
pr := Smallprimes[i];
if pr*pr>result then
BREAK;
while (result > pr) AND (result MOD pr = 0) do
result := result DIV pr;
end;
end;
 
procedure OutNum(lmt,n,CntDivs:Uint64);
var
MaxPrimeFac : Uint64;
begin
MaxPrimeFac := highestDiv(lmt);
writeln(Numb2Usa(lmt):26,'|',Numb2Usa(n):26,'|',Numb2Usa(CntDivs):10);
if MaxPrimeFac > sqr(SmallPrimes[high(tPrimeIdx)]) then
MaxPrimeFac := 0;
writeln(Numb2Usa(lmt):26,'|',Numb2Usa(n):26,'|',Numb2Usa(MaxPrimeFac):15,'|',Numb2Usa(CntDivs):107);
end;
 
Line 682 ⟶ 704:
For i := i to high(tPrimeIdx) do
begin
p := DelCubePrmCubed[i];
if lmt < p then
BREAK;
Line 691 ⟶ 713:
else
cnt += p;
if p >= DelCubePrmCubed[i+1] then
check(p,i+1,not(flip));
end;
Line 699 ⟶ 721:
var
limit : extended;
lmt,dezLmt: Uint64Int64;
lastCntDivs : Uint64;
begin
limit := Z3;
cntdezLmt := lmt1;
while LmtIdx>0 do
Begin
limit *= 10;
dezLmt *=10;
dec(LmtIdx);
end;
lmt := trunc(limit);
 
cnt := lmt;
repeat
CntDivs := 0;
check( cnt := lmt,0,true);
CntDivs := 0;
check(lmt,0,true);
//new apromitaion
inc(lmt,trunc(Z3*(dezlmt-cnt)));
until cnt = dezLmt;
// OutNum(lmt,cnt,CntDivs);
 
//maybe lmt is not cubefree, like 1200 for cnt 1000
//1200 was the only one ....
//faster than checking for cubefree of lmt
repeat
lastCntDivs := CntDivs;
dec(lmt);
cnt := lmt;
CntDivs := 0;
check(lmt,0,true);
until cnt < dezLmt;
 
inc(lmt);
cnt := dezLmt;
CntDivs := lastCntDivs;
 
OutNum(lmt,cnt,CntDivs);
end;
Line 719 ⟶ 766:
Begin
InitSmallPrimes;
InitPrmCubed(PrmCubed);
InitDelCube(DelCube);
Writeln('Tested with Apéry´s Constant approximation of ',Z3:19:15);
write(' ');
writeln('Limit | cube free numbers |countmax ofprim divisionsfactor| divs');
T0 := GetTickCount64;
For i := 0 to 18 do
Line 731 ⟶ 779:
{{out|@home}}
<pre>
 
Limit | cube free numbers |count of divisions
Tested with Apéry´s Constant approximation of 1.202056903159594
1| 1| 0
Limit 12| cube free numbers |max prim 11factor| 1divs
120 1| 101 1| 2 1| 0
1,202 11| 1,002 10| 6 11| 1
12,020 118| 10,001 100| 14 59| 2
120 1,205199| 100 1,001000| 30 109| 6
1,202 12,056019| 999 10,999000| 65 101| 14
12,020 120,569203| 9,999 100,999000| 141 1,693| 30
120 1,205202,690057| 100 1,000,004000| 1,202,057| 30165
1 12,202020,056,903570| 999 10,999000,986000| 1,202,057| 645141
12,020 120,569205,031685| 10 100,000,000,008| 1 20,392743| 301
120 1,205202,690056,315919| 100 1,000,000,014000| 3 215,003461| 645
1 12,202020,056569,903,159022| 1 10,000,000,000,020| 6 1,322,977| 1,465392
12 120,020205,569690,031,595298| 9 100,999000,999000,999,963000| 13 145,823| 3,924003
120 1,205202,690056,315903,959137| 100 1,000,000,000,027000|400,685,634,379| 306,006465
1 12,202020,056569,903031,159,594641| 1 10,000,000,000,000,087| 64 1,498,751| 13,643924
12 120,020205,569690,031315,595,942927| 9 100,999000,999000,999000,999,948000| 139 57,349| 30,261006
120 1,205202,690056,315903,959159,428489| 100 1,000,000,000,000,094000| 74,509,198,733| 30064,023643
1 12,202020,056569,903031,159596,594,285003| 1 10,000,000,000,000,000,317| 646 0|139,394261
120,205,690,315,959,316| 100,000,000,000,000,000| 0|300,023
runtime 0.002 s
1,202,056,903,159,593,905| 1,000,000,000,000,000,000| 89,387|646,394
runtime 0.002013 s real 0m0,019
// as an experiment with factor of 1 for changing approximation.
Tested with Apéry´s Constant approximation of 1.000000000000000
runtime 0.065 s real 0m0,071s
</pre>
 
132

edits