Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
51
Task/Additive-primes/Oberon-07/additive-primes.oberon
Normal file
51
Task/Additive-primes/Oberon-07/additive-primes.oberon
Normal 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.
|
||||
Loading…
Add table
Add a link
Reference in a new issue