Data update
This commit is contained in:
parent
72eb4943cb
commit
4d5544505c
2347 changed files with 62432 additions and 16731 deletions
55
Task/Additive-primes/S-BASIC/additive-primes.basic
Normal file
55
Task/Additive-primes/S-BASIC/additive-primes.basic
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
$constant true = 0FFFFH
|
||||
$constant false = 0
|
||||
$constant limit = 500
|
||||
|
||||
function sum.of.digits(n = integer) = integer
|
||||
var i, sum = integer
|
||||
var s = string
|
||||
var ch = char
|
||||
s = str$(n)
|
||||
sum = 0
|
||||
for i = 2 to len(s)
|
||||
ch = mid(s,i,1)
|
||||
sum = sum + (ch - '0')
|
||||
next i
|
||||
end = sum
|
||||
|
||||
function mod(n, m = integer) = integer
|
||||
end = n - (n / m) * m
|
||||
|
||||
comment
|
||||
build a table of prime numbers using
|
||||
the classic sieve of Erathosthenes
|
||||
end
|
||||
dim integer prime(limit)
|
||||
var i, j, count = integer
|
||||
prime(1) = false
|
||||
for i = 2 to limit
|
||||
prime(i) = true
|
||||
next i
|
||||
rem - strike out multiples of each prime found
|
||||
for i = 2 to sqr(limit)
|
||||
if prime(i) then
|
||||
begin
|
||||
for j = i + i to limit step i
|
||||
prime(j) = false
|
||||
next j
|
||||
end
|
||||
next i
|
||||
|
||||
rem - use the table for the search
|
||||
print "Searching up to"; limit; " for additive primes"
|
||||
count = 0
|
||||
for i = 2 to limit
|
||||
if prime(i) then
|
||||
if prime(sum.of.digits(i)) then
|
||||
begin
|
||||
print using "### "; i;
|
||||
count = count + 1
|
||||
if mod(count, 10) = 0 then print
|
||||
end
|
||||
next i
|
||||
print
|
||||
print count;" were found"
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue