Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,15 +0,0 @@
|
|||
generic
|
||||
type Number is private;
|
||||
Zero : Number;
|
||||
One : Number;
|
||||
Two : Number;
|
||||
with function "+" (X, Y : Number) return Number is <>;
|
||||
with function "*" (X, Y : Number) return Number is <>;
|
||||
with function "/" (X, Y : Number) return Number is <>;
|
||||
with function "mod" (X, Y : Number) return Number is <>;
|
||||
with function ">" (X, Y : Number) return Boolean is <>;
|
||||
package Prime_Numbers is
|
||||
type Number_List is array (Positive range <>) of Number;
|
||||
function Decompose (N : Number) return Number_List;
|
||||
function Is_Prime (N : Number) return Boolean;
|
||||
end Prime_Numbers;
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
package body Prime_Numbers is
|
||||
-- auxiliary (internal) functions
|
||||
function First_Factor (N : Number; Start : Number) return Number is
|
||||
K : Number := Start;
|
||||
begin
|
||||
while ((N mod K) /= Zero) and then (N > (K*K)) loop
|
||||
K := K + One;
|
||||
end loop;
|
||||
if (N mod K) = Zero then
|
||||
return K;
|
||||
else
|
||||
return N;
|
||||
end if;
|
||||
end First_Factor;
|
||||
|
||||
function Decompose (N : Number; Start : Number) return Number_List is
|
||||
F: Number := First_Factor(N, Start);
|
||||
M: Number := N / F;
|
||||
begin
|
||||
if M = One then -- F is the last factor
|
||||
return (1 => F);
|
||||
else
|
||||
return F & Decompose(M, Start);
|
||||
end if;
|
||||
end Decompose;
|
||||
|
||||
-- functions visible from the outside
|
||||
function Decompose (N : Number) return Number_List is (Decompose(N, Two));
|
||||
function Is_Prime (N : Number) return Boolean is
|
||||
(N > One and then First_Factor(N, Two)=N);
|
||||
end Prime_Numbers;
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
with Prime_Numbers, Ada.Text_IO;
|
||||
|
||||
procedure Test_Prime is
|
||||
|
||||
package Integer_Numbers is new
|
||||
Prime_Numbers (Natural, 0, 1, 2);
|
||||
use Integer_Numbers;
|
||||
|
||||
procedure Put (List : Number_List) is
|
||||
begin
|
||||
for Index in List'Range loop
|
||||
Ada.Text_IO.Put (Positive'Image (List (Index)));
|
||||
end loop;
|
||||
end Put;
|
||||
|
||||
begin
|
||||
Put (Decompose (12));
|
||||
end Test_Prime;
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
Program PrimeDecomposition(output);
|
||||
|
||||
type
|
||||
DynArray = array of integer;
|
||||
|
||||
procedure findFactors(n: Int64; var d: DynArray);
|
||||
var
|
||||
divisor, next, rest: Int64;
|
||||
i: integer;
|
||||
begin
|
||||
i := 0;
|
||||
divisor := 2;
|
||||
next := 3;
|
||||
rest := n;
|
||||
while (rest <> 1) do
|
||||
begin
|
||||
while (rest mod divisor = 0) do
|
||||
begin
|
||||
setlength(d, i+1);
|
||||
d[i] := divisor;
|
||||
inc(i);
|
||||
rest := rest div divisor;
|
||||
end;
|
||||
divisor := next;
|
||||
next := next + 2;
|
||||
end;
|
||||
end;
|
||||
|
||||
var
|
||||
factors: DynArray;
|
||||
j: integer;
|
||||
|
||||
begin
|
||||
setlength(factors, 1);
|
||||
findFactors(1023*1024, factors);
|
||||
for j := low(factors) to high(factors) do
|
||||
writeln (factors[j]);
|
||||
end.
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
Program PrimeDecomposition(output);
|
||||
|
||||
type
|
||||
DynArray = array of integer;
|
||||
|
||||
procedure findFactors(n: Int64; var d: DynArray);
|
||||
var
|
||||
divisor, next, rest: Int64;
|
||||
i: integer;
|
||||
begin
|
||||
i := 0;
|
||||
divisor := 2;
|
||||
next := 3;
|
||||
rest := n;
|
||||
while (rest <> 1) do
|
||||
begin
|
||||
while (rest mod divisor = 0) do
|
||||
begin
|
||||
setlength(d, i+1);
|
||||
d[i] := divisor;
|
||||
inc(i);
|
||||
rest := rest div divisor;
|
||||
end;
|
||||
divisor := next;
|
||||
next := next + 2; // try only odd numbers
|
||||
// cut condition: avoid many useless iterations
|
||||
if (rest < divisor * divisor) then
|
||||
begin
|
||||
setlength(d, i+1);
|
||||
d[i] := rest;
|
||||
rest := 1;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
var
|
||||
factors: DynArray;
|
||||
j: integer;
|
||||
|
||||
begin
|
||||
setlength(factors, 1);
|
||||
findFactors(1023*1024, factors);
|
||||
for j := low(factors) to high(factors) do
|
||||
writeln (factors[j]);
|
||||
readln;
|
||||
end.
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
function eratosthenes ($n) {
|
||||
if($n -gt 1){
|
||||
$prime = @(1..($n+1) | foreach{$true})
|
||||
$prime[1] = $false
|
||||
$m = [Math]::Floor([Math]::Sqrt($n))
|
||||
function multiple($i) {
|
||||
for($j = $i*$i; $j -le $n; $j += $i) {
|
||||
$prime[$j] = $false
|
||||
}
|
||||
}
|
||||
multiple 2
|
||||
for($i = 3; $i -le $m; $i += 2) {
|
||||
if($prime[$i]) {multiple $i}
|
||||
}
|
||||
1..$n | where{$prime[$_]}
|
||||
} else {
|
||||
Write-Error "$n is not greater than 1"
|
||||
}
|
||||
}
|
||||
function prime-decomposition ($n) {
|
||||
$array = eratosthenes $n
|
||||
$prime = @()
|
||||
foreach($p in $array) {
|
||||
while($n%$p -eq 0) {
|
||||
$n /= $p
|
||||
$prime += @($p)
|
||||
}
|
||||
}
|
||||
$prime
|
||||
}
|
||||
"$(prime-decomposition 12)"
|
||||
"$(prime-decomposition 100)"
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
function prime-decomposition ($n) {
|
||||
$values = [System.Collections.Generic.List[string]]::new()
|
||||
while ((($n % 2) -eq 0) -and ($n -gt 2)) {
|
||||
$values.Add(2)
|
||||
$n /= 2
|
||||
}
|
||||
for ($i = 3; $n -ge ($i * $i); $i += 2) {
|
||||
if (($n % $i) -eq 0){
|
||||
$values.Add($i)
|
||||
$n /= $i
|
||||
$i -= 2
|
||||
}
|
||||
}
|
||||
$values.Add($n)
|
||||
return $values
|
||||
}
|
||||
"$(prime-decomposition 1000000)"
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
-- 22 Mar 2025
|
||||
include Settings
|
||||
|
||||
say 'PRIME DECOMPOSITION'
|
||||
say version
|
||||
say
|
||||
numeric digits 50
|
||||
call ShowFactors 100,120
|
||||
call ShowFactors 720720
|
||||
call ShowFactors 9007199254740991
|
||||
call ShowFactors 2543821448263974486045199
|
||||
call ShowFactors 340282366920938463463374607431768211455
|
||||
exit
|
||||
|
||||
ShowFactors:
|
||||
arg xx,yy
|
||||
if yy = '' then
|
||||
yy = xx
|
||||
do i = xx to yy
|
||||
call Charout ,i '= '
|
||||
f = Factors(i)
|
||||
if f = 1 then
|
||||
call Charout ,'Prime'
|
||||
else do
|
||||
do j = 1 to f
|
||||
if j < f then
|
||||
call Charout ,fact.j 'x '
|
||||
else
|
||||
call Charout ,fact.j
|
||||
end
|
||||
end
|
||||
say
|
||||
end
|
||||
say Format(Time('e'),,3) 'seconds'
|
||||
say
|
||||
return
|
||||
|
||||
include Functions
|
||||
include Numbers
|
||||
include Sequences
|
||||
include Abend
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
Function PrimeFactors(n)
|
||||
arrP = Split(ListPrimes(n)," ")
|
||||
divnum = n
|
||||
Do Until divnum = 1
|
||||
'The -1 is to account for the null element of arrP
|
||||
For i = 0 To UBound(arrP)-1
|
||||
If divnum = 1 Then
|
||||
Exit For
|
||||
ElseIf divnum Mod arrP(i) = 0 Then
|
||||
divnum = divnum/arrP(i)
|
||||
PrimeFactors = PrimeFactors & arrP(i) & " "
|
||||
End If
|
||||
Next
|
||||
Loop
|
||||
End Function
|
||||
|
||||
Function IsPrime(n)
|
||||
If n = 2 Then
|
||||
IsPrime = True
|
||||
ElseIf n <= 1 Or n Mod 2 = 0 Then
|
||||
IsPrime = False
|
||||
Else
|
||||
IsPrime = True
|
||||
For i = 3 To Int(Sqr(n)) Step 2
|
||||
If n Mod i = 0 Then
|
||||
IsPrime = False
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
End Function
|
||||
|
||||
Function ListPrimes(n)
|
||||
ListPrimes = ""
|
||||
For i = 1 To n
|
||||
If IsPrime(i) Then
|
||||
ListPrimes = ListPrimes & i & " "
|
||||
End If
|
||||
Next
|
||||
End Function
|
||||
|
||||
WScript.StdOut.Write PrimeFactors(CInt(WScript.Arguments(0)))
|
||||
WScript.StdOut.WriteLine
|
||||
Loading…
Add table
Add a link
Reference in a new issue