Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
|
|
@ -0,0 +1,71 @@
|
|||
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;
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Unbounded_Unsigneds; use Unbounded_Unsigneds;
|
||||
with Unbounded_Unsigneds.Primes; use Unbounded_Unsigneds.Primes;
|
||||
|
||||
with Strings_Edit.Unbounded_Unsigned_Edit;
|
||||
use Strings_Edit.Unbounded_Unsigned_Edit;
|
||||
|
||||
procedure Extensible_Prime_Generator is
|
||||
Step : Half_Word := 2;
|
||||
P : Unbounded_Unsigned := Five;
|
||||
Count : Integer := 2;
|
||||
N : Natural := 0;
|
||||
begin
|
||||
Put_Line ("First 20 primes:");
|
||||
Put (" 2 3");
|
||||
loop
|
||||
if Is_Prime (P, 10) = Prime then
|
||||
Count := Count + 1;
|
||||
if Count in 1..20 then
|
||||
Put (' ' & Image (P));
|
||||
if Count = 20 then
|
||||
New_Line;
|
||||
Put_Line ("Primes between 100 and 150:");
|
||||
end if;
|
||||
elsif P >= 100 and then P <= 150 then
|
||||
Put (' ' & Image (P));
|
||||
elsif P >= 7700 and then P <= 8000 then
|
||||
N := N + 1;
|
||||
end if;
|
||||
exit when Count = 10_000;
|
||||
end if;
|
||||
Add (P, Step);
|
||||
if Step = 2 then
|
||||
Step := 4;
|
||||
else
|
||||
Step := 2;
|
||||
end if;
|
||||
end loop;
|
||||
New_Line;
|
||||
Put_Line ("Primes between 7700 and 8000:" & Integer'Image (N));
|
||||
Put_Line ("Prime no." & Integer'Image (Count) & ": " & Image (P));
|
||||
end Extensible_Prime_Generator;
|
||||
Loading…
Add table
Add a link
Reference in a new issue