Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,71 +0,0 @@
|
|||
with Ada.Text_IO, Miller_Rabin;
|
||||
|
||||
procedure Prime_Gen is
|
||||
|
||||
type Num is range 0 .. 2**63-1; -- maximum for the gnat Ada compiler
|
||||
|
||||
MR_Iterations: constant Positive := 25;
|
||||
-- the probability Pr[Is_Prime(N, MR_Iterations) = Probably_Prime]
|
||||
-- is 1 for prime N and < 4**(-MR_Iterations) for composed N
|
||||
|
||||
function Next(P: Num) return Num is
|
||||
N: Num := P+1;
|
||||
package MR is new Miller_Rabin(Num); use MR;
|
||||
begin
|
||||
while not (Is_Prime(N, MR_Iterations) = Probably_Prime) loop
|
||||
N := N + 1;
|
||||
end loop;
|
||||
return N;
|
||||
end Next;
|
||||
|
||||
Current: Num;
|
||||
Count: Num := 0;
|
||||
|
||||
begin
|
||||
-- show the first twenty primes
|
||||
Ada.Text_IO.Put("First 20 primes:");
|
||||
Current := 1;
|
||||
for I in 1 .. 20 loop
|
||||
Current := Next(Current);
|
||||
Ada.Text_IO.Put(Num'Image(Current));
|
||||
end loop;
|
||||
Ada.Text_IO.New_Line;
|
||||
|
||||
-- show the primes between 100 and 150
|
||||
Ada.Text_IO.Put("Primes between 100 and 150:");
|
||||
Current := 99;
|
||||
loop
|
||||
Current := Next(Current);
|
||||
exit when Current > 150;
|
||||
Ada.Text_IO.Put(Num'Image(Current));
|
||||
end loop;
|
||||
Ada.Text_IO.New_Line;
|
||||
|
||||
-- count primes between 7700 and 8000
|
||||
Ada.Text_IO.Put("Number of primes between 7700 and 8000:");
|
||||
Current := 7699;
|
||||
loop
|
||||
Current := Next(Current);
|
||||
exit when Current > 8000;
|
||||
Count := Count + 1;
|
||||
end loop;
|
||||
Ada.Text_IO.Put_Line(Num'Image(Count));
|
||||
|
||||
Count := 10;
|
||||
Ada.Text_IO.Put_Line("Print the K_i'th prime, for $K=10**i:");
|
||||
begin
|
||||
loop
|
||||
Current := 1;
|
||||
for I in 1 .. Count loop
|
||||
Current := Next(Current);
|
||||
end loop;
|
||||
Ada.Text_IO.Put(Num'Image(Count) & "th prime:" &
|
||||
Num'Image(Current));
|
||||
Count := Count * 10;
|
||||
end loop;
|
||||
exception
|
||||
when Constraint_Error =>
|
||||
Ada.Text_IO.Put_Line(" can't compute the" & Num'Image(Count) &
|
||||
"th prime:");
|
||||
end;
|
||||
end;
|
||||
|
|
@ -34,7 +34,7 @@ partial_sum x y = pq where
|
|||
q_ab = q_ac*q_cb
|
||||
|
||||
-- c is the real constant that is used in the formula for primes
|
||||
-- c = sum_{1<i} p_i / (2i+1)!
|
||||
-- c = sum_{1<=i} p_i / (2i+1)!
|
||||
-- where p_i is i-th prime.
|
||||
-- This will work for any sequence of integers p, where |p_n| < 2n(2n+1) * 0.375
|
||||
c = crMemoize f where
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
-- 22 Mar 2025
|
||||
include Settings
|
||||
-- 23 Aug 2025
|
||||
include Setting
|
||||
|
||||
say 'EXTENSIBLE PRIME GENERATOR'
|
||||
say version
|
||||
|
|
@ -28,7 +28,7 @@ return
|
|||
|
||||
Between100and150:
|
||||
procedure expose prim.
|
||||
say 'Prime numbers between 100 and 150 are:'
|
||||
say 'Prime numbers between 100...150 are:'
|
||||
n = 0
|
||||
do i = 1
|
||||
a = prim.i
|
||||
|
|
@ -46,7 +46,7 @@ return
|
|||
|
||||
Between7700and8000:
|
||||
procedure expose prim.
|
||||
say 'Prime numbers between 77022 Mar 2025:'
|
||||
say 'Prime numbers between 7700...8000:'
|
||||
n = 0
|
||||
do i = 1
|
||||
a = prim.i
|
||||
|
|
@ -76,7 +76,4 @@ say 'The 5500000th prime is' prim.5500000
|
|||
say
|
||||
return
|
||||
|
||||
include Functions
|
||||
include Sequences
|
||||
include Numbers
|
||||
include Abend
|
||||
include Math
|
||||
|
|
|
|||
|
|
@ -1,93 +0,0 @@
|
|||
'uses variant booleans for the sieve, so 16 bytes per bit, a little wasteful!
|
||||
|
||||
Option Explicit
|
||||
|
||||
Sub sieveit(maxi) 'increases sieve size up to maxi and sieves the added part
|
||||
Dim lasttop,a,b,c,i,j
|
||||
lasttop=UBound(primes)
|
||||
If maxi>lasttop Then
|
||||
ReDim preserve primes(maxi)
|
||||
print vbcrlf &"(sieving from " & lasttop & " up to " & maxi &")"& vbCrLf
|
||||
For i=lasttop+1 To maxi
|
||||
primes(i)=True
|
||||
next
|
||||
For i=2 To Int(Sqr(lasttop))
|
||||
If primes(i)=True Then
|
||||
a=lasttop\i
|
||||
b=maxi\i
|
||||
c= i*a
|
||||
For j=a To b
|
||||
primes(c)=False
|
||||
c=c+i
|
||||
Next
|
||||
End if
|
||||
Next
|
||||
For i=Int(Sqr(lasttop)) To Int(Sqr(maxi))
|
||||
If primes(i)=True Then
|
||||
c=i*i
|
||||
While c<=maxi
|
||||
primes(c)=False
|
||||
c=c+i
|
||||
wend
|
||||
End if
|
||||
next
|
||||
End if
|
||||
End Sub
|
||||
|
||||
function nth(n) 'returns the nth prime (sieves if needed)
|
||||
Dim cnt,i,m
|
||||
m=Int(n *(Log(n)+Log(Log(n))))
|
||||
|
||||
If m>UBound(primes) Then sieveit (m)
|
||||
i=1
|
||||
Do
|
||||
i=i+1
|
||||
If primes(i) Then cnt=cnt+1
|
||||
Loop until cnt=n
|
||||
nth=i
|
||||
End function
|
||||
|
||||
Sub printprimes (x1, x2,p) ' counts and prints (if p=true) primes between x1 and x2 (sieves if needed)
|
||||
Dim lasttop,n,cnt,i
|
||||
If x2> UBound(primes) Then sieveit(x2)
|
||||
print "primes in range " & x1 & " To " & x2 & vbCrLf
|
||||
cnt=0
|
||||
For i=x1 To x2
|
||||
If primes(i) Then
|
||||
If p Then print i & vbTab
|
||||
cnt=cnt+1
|
||||
End if
|
||||
next
|
||||
print vbCrLf & "Count: " & cnt
|
||||
End Sub
|
||||
|
||||
|
||||
Sub print(s):
|
||||
On Error Resume Next
|
||||
WScript.stdout.WriteLine (s)
|
||||
If err= &h80070006& Then WScript.Echo " Please run this script with CScript": WScript.quit
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
' main program-------------------------------------------
|
||||
Dim n
|
||||
' initialization of the array of booleans
|
||||
reDim Primes(2)
|
||||
primes(0) = False
|
||||
Primes(1) = False
|
||||
Primes(2) = True
|
||||
|
||||
'Show the first twenty primes.
|
||||
n=nth(20)
|
||||
printprimes 1,n,1
|
||||
|
||||
'Show the primes between 100 and 150.
|
||||
printprimes 100,150,1
|
||||
|
||||
'Show the number of primes between 7,700 and 8,000.
|
||||
printprimes 7700,8000,0
|
||||
|
||||
'Show the 10,000th prime.
|
||||
n= nth(10000)
|
||||
print n & " is the " & 10000 & "th prime"
|
||||
Loading…
Add table
Add a link
Reference in a new issue