Data update

This commit is contained in:
Ingy döt Net 2024-10-16 18:07:41 -07:00
parent 81fd053722
commit 52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions

View file

@ -0,0 +1,51 @@
MODULE AdditivePrimes;
IMPORT
Out;
CONST
Max = 500;
VAR
Count, n :INTEGER;
Prime :ARRAY Max + 1 OF BOOLEAN;
PROCEDURE DigitSum( n :INTEGER ):INTEGER;
VAR result :INTEGER;
BEGIN
result := 0;
IF n < 10 THEN result := n
ELSE result := ( n MOD 10 ) + DigitSum( n DIV 10 )
END
RETURN result
END DigitSum;
PROCEDURE Sieve;
VAR i, j :INTEGER;
BEGIN
Prime[ 0 ] := FALSE; Prime[ 1 ] := FALSE;
FOR i := 2 TO Max DO Prime[ i ] := TRUE END;
FOR i := 2 TO Max DIV 2 DO
IF Prime[ i ] THEN
j := i * 2;
WHILE j <= Max DO
Prime[ j ] := FALSE;
INC( j, i )
END
END
END
END Sieve;
BEGIN
Sieve;
FOR n := 2 TO Max DO
IF Prime[ n ] & Prime[ DigitSum( n ) ] THEN
Out.Int( n, 4 );
INC( Count );
IF Count MOD 20 = 0 THEN Out.Ln END
END
END;
Out.Ln;Out.String( "There are " );Out.Int( Count, 1 );
Out.String( " additive primes less than " );Out.Int( Max, 1 );
Out.String( "." );Out.Ln
END AdditivePrimes.

View file

@ -0,0 +1,60 @@
include Settings
say version; say 'Additive primes'; say
arg n
numeric digits 16
if n = '' then
n = -500
show = (n > 0); n = Abs(n)
a = AdditivePrimes(n)
if show then do
do i = 1 to a
call Charout ,right(addi.additiveprime.i,8)' '
if i//10 = 0 then
say
end
say
end
say a 'additive primes found below' n
say Time('e') 'seconds'
exit
Additiveprimes:
/* Additive prime numbers */
procedure expose addi. prim.
arg x
/* Init */
addi. = 0
/* Fast values */
if x < 2 then
return 0
if x < 101 then do
a = '2 3 5 7 11 23 29 41 43 47 61 67 83 89 999'
do n = 1 to Words(a)
w = Word(a,n)
if w > x then
leave
addi.additiveprime.n = w
end
n = n-1; addi.0 = n
return n
end
/* Get primes */
p = Primes(x)
/* Collect additive primes */
n = 0
do i = 1 to p
q = prim.prime.i; s = 0
do j = 1 to Length(q)
s = s+Substr(q,j,1)
end
if IsPrime(s) then do
n = n+1; addi.additiveprime.n = q
end
end
/* Return number of additive primes */
return n
include Numbers
include Functions
include Abend