Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,48 @@
begin
comment - return a mod b;
integer procedure mod(a, b);
value a, b; integer a, b;
begin
mod := a - entier(a/b) * b;
end;
comment - return true if n is a semi-prime number;
boolean procedure semiprime(n);
value n; integer n;
begin
integer i, count;
count := 1;
i := 2;
for i := i while (i * i) <= n do
begin
if mod(n, i) = 0 then
begin
count := count + 1;
n := n / i;
end
else
i := i + 1;
end;
semiprime := (count = 2);
end;
integer i, limit, found;
limit := 100;
outstring(1,"Searching up to");
outinteger(1,limit);
outstring(1,"for semi-primes:\n");
found := 0;
for i := 3 step 1 until limit do
begin
if semiprime(i) then
begin
outinteger(1,i);
found := found + 1;
if mod(found, 10) = 0 then outstring(1,"\n");
end;
end;
outstring(1,"\n");
outinteger(1,found);
outstring(1,"were found");
end

View file

@ -0,0 +1,44 @@
begin
comment - return a mod b;
integer function mod(a, b);
integer a, b;
begin
mod := a - (a/b) * b;
end;
comment - return 1 if n is semi-prime, otherwise 0;
integer function semiprime(n);
integer n;
begin
integer i, count;
count := 1;
i := 2;
while (i * i) <= n do
begin
if mod(n, i) = 0 then
begin
count := count + 1;
n := n / i;
end
else
i := i + 1;
end;
semiprime := (if count = 2 then 1 else 0);
end;
integer i, limit, found;
limit := 100;
found := 0;
for i := 3 step 1 until limit do
begin
if semiprime(i) = 1 then
begin
writeon(i);
found := found + 1;
if mod(found, 10) = 0 then write("");
end;
end;
write(found, " were found");
end

View file

@ -0,0 +1,23 @@
100 REM Semiprime
110 DECLARE EXTERNAL FUNCTION FactorsCnt
120 INPUT PROMPT "Enter an integer: ": N
130 IF FactorsCnt(N) = 2 THEN
140 PRINT "It is a semiprime."
150 ELSE
160 PRINT "It is not a semiprime."
170 END IF
180 END
190 REM
200 EXTERNAL FUNCTION FactorsCnt(N)
210 LET AN = ABS(N)
220 LET Count = 0
230 IF AN >= 2 THEN
240 FOR F = 2 TO AN
250 DO WHILE MOD(AN, F) = 0
260 LET Count = Count + 1
270 LET AN = INT(AN / F)
280 LOOP
290 NEXT F
300 END IF
310 LET FactorsCnt = Count
320 END FUNCTION

View file

@ -0,0 +1,21 @@
with Prime_Numbers, Ada.Text_IO;
procedure Test_Semiprime is
package Integer_Numbers is new
Prime_Numbers (Natural, 0, 1, 2);
use Integer_Numbers;
begin
for N in 1 .. 100 loop
if Decompose(N)'Length = 2 then -- N is a semiprime;
Ada.Text_IO.Put(Integer'Image(Integer(N)));
end if;
end loop;
Ada.Text_IO.New_Line;
for N in 1675 .. 1680 loop
if Decompose(N)'Length = 2 then -- N is a semiprime;
Ada.Text_IO.Put(Integer'Image(Integer(N)));
end if;
end loop;
end Test_Semiprime;

View file

@ -0,0 +1,27 @@
include "NSLog.incl"
BOOL local fn Semiprime( n as int )
int a = 2, c = 0
while ( c < 3 && n > 1 )
if ( n % a ) == 0
n = n / a
c++
else
a++
end if
wend
if ( c == 2 ) then return YES
end fn = NO
void local fn FindSemiprimes( limit as int )
NSLog( @"Semiprimes between 0 and %d:\n", limit )
int count = 0
for int i = 1 to limit
if ( fn Semiprime(i) == YES ) then NSLog( @"%4d\b", i ) : count++ : if count % 10 == 0 then NSLog( @"" )
next
end fn
fn FindSemiprimes( 100 )
HandleEvents

View file

@ -0,0 +1,37 @@
MODULE Semiprime;
FROM STextIO IMPORT
SkipLine, WriteLn, WriteString;
FROM SWholeIO IMPORT
ReadInt;
VAR
N: INTEGER;
PROCEDURE FactorsCnt(N: INTEGER): CARDINAL;
VAR
Count, F, AN: CARDINAL;
BEGIN
AN := ABS(N);
Count := 0;
IF AN >= 2 THEN
FOR F := 2 TO AN DO
WHILE AN MOD F = 0 DO
Count := Count + 1;
AN := AN DIV F
END
END
END;
RETURN Count
END FactorsCnt;
BEGIN
WriteString("Enter an integer: ");
ReadInt(N);
SkipLine;
IF FactorsCnt(N) = 2 THEN
WriteString("It is a semiprime.")
ELSE
WriteString("It is not a semiprime.")
END;
WriteLn;
END Semiprime.

View file

@ -0,0 +1,33 @@
' Semiprime
BEGIN DEF
pointer word PtrCount~)
SUB CalcCount(N%, PtrCount~)
BEGIN CODE
PRINT "Enter an integer: "
INPUT (TmpStr$)
N% = VAL(TmpStr$)
PRINT "\n"
CALL CalcCount(N%, VARPTR(Count%))
IF Count% = 2 THEN
PRINT "It is a semiprime.\n"
ELSE
PRINT "It is not a semiprime.\n"
ENDIF
END
SUB CalcCount(N%, PtrCount~)
N% = ABS(N%)
Count% = 0
IF N% >= 2 THEN
FOR Factor% = 2 TO N%
NModFactor% = N% MOD Factor%
WHILE NModFactor% = 0
Count% = Count% + 1
N% = N% \ Factor%
NModFactor% = N% MOD Factor%
WEND
NEXT
ENDIF
[PtrCount~] = Count%
END SUB

View file

@ -0,0 +1,47 @@
MODULE SemiPrimes;
IMPORT Math, Out;
(* returns TRUE if n is semi-prime, FALSE otherwise *)
(* n is semi prime if it has exactly two prime factors *)
PROCEDURE isSemiPrime( n : INTEGER ) : BOOLEAN;
VAR factor, factorCount, maxLowFactor, otherFactor : INTEGER;
BEGIN
(* We only need to consider factors between 2 and *)
(* sqrt( n ) inclusive. If there is only one of these *)
(* then it must be a prime factor and so the number *)
(* is semi prime *)
factorCount := 0;
maxLowFactor := FLOOR( Math.sqrt( FLT( ABS( n ) ) ) );
factor := 2;
WHILE ( factor <= maxLowFactor ) & ( factorCount < 2 ) DO
IF n MOD factor = 0 THEN
INC( factorCount );
(* check the factor isn't a repeated factor *)
IF n # factor * factor THEN
(* the factor isn't the square root *)
otherFactor := n DIV factor;
IF otherFactor MOD factor = 0 THEN
(* have a repeated factor *)
INC( factorCount )
END
END
END;
INC( factor );
END
RETURN factorCount = 1
END isSemiPrime;
PROCEDURE showSemiPrimes( title : ARRAY OF CHAR; fromN, toN : INTEGER );
VAR i : INTEGER;
BEGIN
Out.String( title );Out.String( ":" );Out.Ln;Out.String( " " );
FOR i := fromN TO toN DO
IF isSemiPrime( i ) THEN Out.String( " " );Out.Int( i, 0 ) END
END;
Out.Ln
END showSemiPrimes;
BEGIN
showSemiPrimes( "semi primes below 100", 1, 99 );
showSemiPrimes( "semi primes between 1670 and 1690", 1670, 1690 )
END SemiPrimes.

View file

@ -0,0 +1,16 @@
local function semiprime(n)
if n < 3 then return false end
local nf = 0
for i = 2, n do
while n % i == 0 do
if nf == 2 then return false end
nf += 1
n //= i
end
end
return nf == 2
end
for v = 1675, 1680 do
print($"{v} -> {semiprime(v) ? "is" : "isn't"} semi-prime")
end

View file

@ -0,0 +1,26 @@
function isPrime ($n) {
if ($n -le 1) {$false}
elseif (($n -eq 2) -or ($n -eq 3)) {$true}
else{
$m = [Math]::Floor([Math]::Sqrt($n))
(@(2..$m | where {($_ -lt $n) -and ($n % $_ -eq 0) }).Count -eq 0)
}
}
function semiprime ($n) {
if($n -gt 3) {
$lim = [Math]::Floor($n/2)+1
$i = 2
while(($i -lt $lim) -and ($n%$i -ne 0)){ $i += 1}
if($i -eq $lim){@()}
elseif(-not (isPrime ($n/$i))){@()}
else{@($i,($n/$i))}
} else {@()}
}
$OFS = " x "
"1679: $(semiprime 1679)"
"87: $(semiprime 87)"
"25: $(semiprime 25)"
"12: $(semiprime 12)"
"6: $(semiprime 6)"
$OFS = " "
"semiprime from 1 to 100: $(1..100 | where {semiprime $_})"

View file

@ -0,0 +1,24 @@
' Semiprime
DECLARE FUNCTION Count% (BYVAL N%)
INPUT "Enter an integer: ", N%
IF Count%(N%) = 2 THEN
PRINT "It is a semiprime."
ELSE
PRINT "It is not a semiprime."
END IF
END
FUNCTION Count% (BYVAL N%)
N% = ABS(N%)
Result% = 0
IF N% >= 2 THEN
FOR Factor% = 2 TO N%
WHILE N% MOD Factor% = 0
Result% = Result% + 1
N% = N% \ Factor%
WEND
NEXT Factor%
END IF
Count% = Result%
END FUNCTION