Greatest prime dividing the n-th cubefree number: Difference between revisions
Content added Content deleted
(→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: | Line 553: | ||
</pre> |
</pre> |
||
===resursive alternative=== |
===resursive alternative=== |
||
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"> |
<syntaxhighlight lang="pascal"> |
||
program CubeFree3; |
program CubeFree3; |
||
Line 568: | Line 568: | ||
const |
const |
||
//Apéry's Constant |
//Apéry's Constant |
||
Z3 = 1.20205690315959428539973816151144999; |
Z3 = 1.20205690315959428539973816151144999; |
||
RezZ3 = 0.831907372580707468683126278821530734417; |
RezZ3 = 0.831907372580707468683126278821530734417; |
||
{ |
{ |
||
Line 580: | Line 580: | ||
tPrimes = array[tPrimeIdx] of Uint32; |
tPrimes = array[tPrimeIdx] of Uint32; |
||
tDl3 = UInt64; |
tDl3 = UInt64; |
||
tPrmCubed = array[tPrimeIdx] of tDl3; |
|||
var |
var |
||
{$ALIGN 8} |
{$ALIGN 8} |
||
SmallPrimes: tPrimes; |
SmallPrimes: tPrimes; |
||
PrmCubed : tPrmCubed; |
|||
procedure InitSmallPrimes; |
procedure InitSmallPrimes; |
||
Line 629: | Line 629: | ||
end; |
end; |
||
procedure |
procedure InitPrmCubed(var DC:tPrmCubed); |
||
var |
var |
||
i,q : Uint64; |
i,q : Uint64; |
||
Line 664: | Line 664: | ||
dec(j,4); |
dec(j,4); |
||
end; |
end; |
||
end; |
|||
end; |
|||
function highestDiv(n: uint64):Uint64; |
|||
//can test til 2642246^2 ~ 6,98E12 |
|||
var |
|||
pr : Uint64; |
|||
i : integer; |
|||
begin |
|||
⚫ | |||
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; |
||
end; |
end; |
||
procedure OutNum(lmt,n,CntDivs:Uint64); |
procedure OutNum(lmt,n,CntDivs:Uint64); |
||
var |
|||
MaxPrimeFac : Uint64; |
|||
begin |
begin |
||
MaxPrimeFac := highestDiv(lmt); |
|||
⚫ | |||
if MaxPrimeFac > sqr(SmallPrimes[high(tPrimeIdx)]) then |
|||
MaxPrimeFac := 0; |
|||
⚫ | |||
end; |
end; |
||
Line 682: | Line 704: | ||
For i := i to high(tPrimeIdx) do |
For i := i to high(tPrimeIdx) do |
||
begin |
begin |
||
p := |
p := PrmCubed[i]; |
||
if lmt < p then |
if lmt < p then |
||
BREAK; |
BREAK; |
||
Line 691: | Line 713: | ||
else |
else |
||
cnt += p; |
cnt += p; |
||
if p >= |
if p >= PrmCubed[i+1] then |
||
check(p,i+1,not(flip)); |
check(p,i+1,not(flip)); |
||
end; |
end; |
||
Line 699: | Line 721: | ||
var |
var |
||
limit : extended; |
limit : extended; |
||
lmt: |
lmt,dezLmt: Int64; |
||
lastCntDivs : Uint64; |
|||
begin |
begin |
||
limit := Z3; |
limit := Z3; |
||
⚫ | |||
while LmtIdx>0 do |
while LmtIdx>0 do |
||
Begin |
Begin |
||
limit *= 10; |
limit *= 10; |
||
dezLmt *=10; |
|||
dec(LmtIdx); |
dec(LmtIdx); |
||
end; |
end; |
||
lmt := trunc(limit); |
lmt := trunc(limit); |
||
⚫ | |||
repeat |
|||
⚫ | |||
cnt := lmt; |
|||
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); |
OutNum(lmt,cnt,CntDivs); |
||
end; |
end; |
||
Line 719: | Line 766: | ||
Begin |
Begin |
||
InitSmallPrimes; |
InitSmallPrimes; |
||
InitPrmCubed(PrmCubed); |
|||
InitDelCube(DelCube); |
|||
Writeln('Tested with Apéry´s Constant approximation of ',Z3:19:15); |
|||
write(' '); |
write(' '); |
||
writeln('Limit | cube free numbers | |
writeln('Limit | cube free numbers |max prim factor| divs'); |
||
T0 := GetTickCount64; |
T0 := GetTickCount64; |
||
For i := 0 to 18 do |
For i := 0 to 18 do |
||
Line 731: | Line 779: | ||
{{out|@home}} |
{{out|@home}} |
||
<pre> |
<pre> |
||
Limit | cube free numbers |count of divisions |
|||
Tested with Apéry´s Constant approximation of 1.202056903159594 |
|||
1| 1| 0 |
|||
Limit | cube free numbers |max prim factor| divs |
|||
1| 1| 1| 0 |
|||
11| 10| 11| 1 |
|||
118| 100| 59| 2 |
|||
1,199| 1,000| 109| 6 |
|||
12,019| 10,000| 101| 14 |
|||
120,203| 100,000| 1,693| 30 |
|||
1,202,057| 1,000,000| 1,202,057| 65 |
|||
12,020,570| 10,000,000| 1,202,057| 141 |
|||
120,205,685| 100,000,000| 20,743| 301 |
|||
1,202,056,919| 1,000,000,000| 215,461| 645 |
|||
12,020,569,022| 10,000,000,000| 1,322,977| 1,392 |
|||
120,205,690,298| 100,000,000,000| 145,823| 3,003 |
|||
1,202,056,903,137| 1,000,000,000,000|400,685,634,379| 6,465 |
|||
12,020,569,031,641| 10,000,000,000,000| 1,498,751| 13,924 |
|||
120,205,690,315,927| 100,000,000,000,000| 57,349| 30,006 |
|||
1,202,056,903,159,489| 1,000,000,000,000,000| 74,509,198,733| 64,643 |
|||
12,020,569,031,596,003| 10,000,000,000,000,000| 0|139,261 |
|||
120,205,690,315,959,316| 100,000,000,000,000,000| 0|300,023 |
|||
⚫ | |||
1,202,056,903,159,593,905| 1,000,000,000,000,000,000| 89,387|646,394 |
|||
⚫ | |||
// 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> |
</pre> |
||