Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,162 +0,0 @@
|
|||
program SquareFree;
|
||||
{$IFDEF FPC}
|
||||
{$MODE DELPHI}
|
||||
{$ELSE}
|
||||
{$APPTYPE CONSOLE}
|
||||
{$ENDIF}
|
||||
const
|
||||
//needs 1e10 Byte = 10 Gb maybe someone got 128 Gb :-) nearly linear time
|
||||
BigLimit = 10*1000*1000*1000;
|
||||
TRILLION = 1000*1000*1000*1000;
|
||||
primeLmt = trunc(sqrt(TRILLION+150));
|
||||
|
||||
var
|
||||
primes : array of byte;
|
||||
sieve : array of byte;
|
||||
|
||||
procedure initPrimes;
|
||||
var
|
||||
i,lmt,dp :NativeInt;
|
||||
Begin
|
||||
setlength(primes,80000);
|
||||
setlength(sieve,primeLmt);
|
||||
sieve[0] := 1;
|
||||
sieve[1] := 1;
|
||||
i := 2;
|
||||
repeat
|
||||
IF sieve[i] = 0 then
|
||||
Begin
|
||||
lmt:= i*i;
|
||||
while lmt<primeLmt do
|
||||
Begin
|
||||
sieve[lmt] := 1;
|
||||
inc(lmt,i);
|
||||
end;
|
||||
end;
|
||||
inc(i);
|
||||
until i*i>=primeLmt;
|
||||
//extract difference of primes
|
||||
i := 0;
|
||||
lmt := 0;
|
||||
dp := 0;
|
||||
repeat
|
||||
IF sieve[i] = 0 then
|
||||
Begin
|
||||
primes[lmt] := dp;
|
||||
dp := 0;
|
||||
inc(lmt);
|
||||
end;
|
||||
inc(dp);
|
||||
inc(i);
|
||||
until i >primeLmt;
|
||||
setlength(sieve,0);
|
||||
setlength(Primes,lmt+1);
|
||||
end;
|
||||
|
||||
procedure SieveSquares;
|
||||
//mark all powers >=2 of prime => all powers = 2 is sufficient
|
||||
var
|
||||
pSieve : pByte;
|
||||
i,sq,k,prime : NativeInt;
|
||||
Begin
|
||||
pSieve := @sieve[0];
|
||||
prime := 0;
|
||||
For i := 0 to High(primes) do
|
||||
Begin
|
||||
prime := prime+primes[i];
|
||||
sq := prime*prime;
|
||||
k := sq;
|
||||
if sq > BigLimit then
|
||||
break;
|
||||
repeat
|
||||
pSieve[k] := 1;
|
||||
inc(k,sq);
|
||||
until k> BigLimit;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure Count_x10;
|
||||
var
|
||||
pSieve : pByte;
|
||||
i,lmt,cnt: NativeInt;
|
||||
begin
|
||||
writeln(' square free count');
|
||||
writeln('[1 to limit]');
|
||||
|
||||
pSieve := @sieve[0];
|
||||
lmt := 10;
|
||||
i := 1;
|
||||
cnt := 0;
|
||||
repeat
|
||||
while i <= lmt do
|
||||
Begin
|
||||
inc(cnt,ORD(pSieve[i] = 0));
|
||||
inc(i);
|
||||
end;
|
||||
writeln(lmt:12,' ',cnt:12);
|
||||
IF lmt >= BigLimit then
|
||||
BREAK;
|
||||
lmt := lmt*10;
|
||||
IF lmt >BigLimit then
|
||||
lmt := BigLimit;
|
||||
until false;
|
||||
end;
|
||||
|
||||
function TestSquarefree(N:Uint64):boolean;
|
||||
var
|
||||
i,prime,sq : NativeUint;
|
||||
Begin
|
||||
prime := 0;
|
||||
result := false;
|
||||
For i := 0 to High(primes) do
|
||||
Begin
|
||||
prime := prime+primes[i];
|
||||
sq := sqr(prime);
|
||||
IF sq> N then
|
||||
BREAK;
|
||||
IF N MOD sq = 0 then
|
||||
EXIT;
|
||||
end;
|
||||
result := true;
|
||||
end;
|
||||
var
|
||||
i,k : NativeInt;
|
||||
Begin
|
||||
InitPrimes;
|
||||
setlength(sieve,BigLimit+1);
|
||||
SieveSquares;
|
||||
|
||||
writeln('Square free numbers from 1 to 145');
|
||||
k := 80 div 4;
|
||||
For i := 1 to 145 do
|
||||
If sieve[i] = 0 then
|
||||
Begin
|
||||
write(i:4);
|
||||
dec(k);
|
||||
IF k = 0 then
|
||||
Begin
|
||||
writeln;
|
||||
k := 80 div 4;
|
||||
end;
|
||||
end;
|
||||
writeln;writeln;
|
||||
|
||||
writeln('Square free numbers from ',TRILLION,' to ',TRILLION+145);
|
||||
k := 4;
|
||||
For i := TRILLION to TRILLION+145 do
|
||||
Begin
|
||||
if TestSquarefree(i) then
|
||||
Begin
|
||||
write(i:20);
|
||||
dec(k);
|
||||
IF k = 0 then
|
||||
Begin
|
||||
writeln;
|
||||
k := 4;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
writeln;writeln;
|
||||
|
||||
Count_x10;
|
||||
end.
|
||||
|
|
@ -1,29 +1,27 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">square_frees</span><span style="color: #0000FF;">(</span><span style="color: #004080;">atom</span> <span style="color: #000000;">start</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">finish</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">maxprime</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">get_maxprime</span><span style="color: #0000FF;">(</span><span style="color: #000000;">finish</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">while</span> <span style="color: #000000;">start</span><span style="color: #0000FF;"><=</span><span style="color: #000000;">finish</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #7060A8;">square_free</span><span style="color: #0000FF;">(</span><span style="color: #000000;">start</span><span style="color: #0000FF;">,</span><span style="color: #000000;">maxprime</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #000000;">res</span> <span style="color: #0000FF;">&=</span> <span style="color: #000000;">start</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #000000;">start</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #000000;">res</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
with javascript_semantics
|
||||
function square_frees(atom start, finish)
|
||||
sequence res = {}
|
||||
integer maxprime = get_maxprime(finish)
|
||||
while start<=finish do
|
||||
if square_free(start,maxprime) then
|
||||
res &= start
|
||||
end if
|
||||
start += 1
|
||||
end while
|
||||
return res
|
||||
end function
|
||||
|
||||
<span style="color: #008080;">procedure</span> <span style="color: #000000;">show_range</span><span style="color: #0000FF;">(</span><span style="color: #004080;">atom</span> <span style="color: #000000;">start</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">finish</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">jb</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">string</span> <span style="color: #000000;">fmt</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">square_frees</span><span style="color: #0000FF;">(</span><span style="color: #000000;">start</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">finish</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"There are %d square-free integers from %,d to %,d:\n%s\n"</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #0000FF;">{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">),</span><span style="color: #000000;">start</span><span style="color: #0000FF;">,</span><span style="color: #000000;">finish</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">jb</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">fmt</span><span style="color: #0000FF;">)})</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
|
||||
<span style="color: #000000;">show_range</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">145</span><span style="color: #0000FF;">,</span><span style="color: #000000;">20</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%4d"</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #000000;">show_range</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1e12</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1e12</span><span style="color: #0000FF;">+</span><span style="color: #000000;">145</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%14d"</span><span style="color: #0000FF;">)</span>
|
||||
procedure show_range(atom start, finish, integer jb, string fmt)
|
||||
sequence res = square_frees(start, finish)
|
||||
printf(1,"There are %d square-free integers from %,d to %,d:\n%s\n",
|
||||
{length(res),start,finish,join_by(res,1,jb,"","\n",fmt)})
|
||||
end procedure
|
||||
show_range(1,145,20,"%4d")
|
||||
show_range(1e12,1e12+145,5,"%14d")
|
||||
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\nNumber of square-free integers:\n"</span><span style="color: #0000FF;">);</span>
|
||||
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">2</span> <span style="color: #008080;">to</span> <span style="color: #000000;">6</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">lim</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">power</span><span style="color: #0000FF;">(</span><span style="color: #000000;">10</span><span style="color: #0000FF;">,</span><span style="color: #000000;">i</span><span style="color: #0000FF;">),</span>
|
||||
<span style="color: #000000;">len</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">square_frees</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">lim</span><span style="color: #0000FF;">))</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" from %,d to %,d = %,d\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">lim</span><span style="color: #0000FF;">,</span><span style="color: #000000;">len</span><span style="color: #0000FF;">})</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
|
||||
<!--
|
||||
printf(1,"\nNumber of square-free integers:\n");
|
||||
for i=2 to 6 do
|
||||
integer lim = power(10,i),
|
||||
len = length(square_frees(1,lim))
|
||||
printf(1," from %,d to %,d = %,d\n", {1,lim,len})
|
||||
end for
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
include Settings
|
||||
-- 24 Aug 2025
|
||||
include Setting
|
||||
|
||||
say 'SQUARE-FREE INTEGERS - 6 Mar 2025'
|
||||
say 'SQUARE-FREE INTEGERS'
|
||||
say version
|
||||
say
|
||||
numeric digits 5
|
||||
|
|
@ -74,7 +75,4 @@ say '--------------'
|
|||
say Format(Time('e'),,3) 'seconds'
|
||||
return
|
||||
|
||||
include Numbers
|
||||
include Sequences
|
||||
include Functions
|
||||
include Abend
|
||||
include Math
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
Sqf ← ≠0/↧◿⊸(×.↘2⇡+1⌊√)
|
||||
⟜⧻▽⊸≡Sqf +1⇡145
|
||||
⟜⧻▽⊸≡Sqf +1e12+1⇡145
|
||||
# Find all squares and their multiples, and mask them out.
|
||||
▽:⇡⟜(¬±°⊚/◇⊂≡(□×⇡+1)⌊÷:⟜(.×.↘2⇡√.))1000000
|
||||
⊙◌≡(/+<)⇌[⍥(×10.)4 100]¤
|
||||
Sqf ← ≠0/↧◿⊸(˙×↘2⇡+1⌊√)
|
||||
⧻⟜▽⊸≡Sqf +1⇡145
|
||||
⧻⟜▽⊸≡Sqf +1e12+1⇡145
|
||||
# Find all squares and their multiples, mask them out.
|
||||
⍉▽>0/↧⊸⊞◿⊃(˙ט▽⟜=⟜(⊣°/×)↘2⇡⌊+1√|↘1⇡)2000000
|
||||
# Count them.
|
||||
≡(⧻▽⊸≤)⊢[⍥⊸×₁₀ 5 100]¤
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue