Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
37
Task/Additive-primes/FutureBasic/additive-primes.basic
Normal file
37
Task/Additive-primes/FutureBasic/additive-primes.basic
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
local fn IsPrime( n as NSUInteger ) as BOOL
|
||||
NSUInteger i
|
||||
BOOL result = YES
|
||||
|
||||
if ( n < 2 ) then exit fn = NO
|
||||
for i = 2 to n + 1
|
||||
if ( i * i <= n ) and ( n mod i == 0 )
|
||||
exit fn = NO
|
||||
end if
|
||||
next
|
||||
end fn = result
|
||||
|
||||
local fn DigSum( n as NSUInteger ) as NSUInteger
|
||||
NSUInteger s = 0
|
||||
while ( n > 0 )
|
||||
s += ( n mod 10 )
|
||||
n /= 10
|
||||
wend
|
||||
end fn = s
|
||||
|
||||
void local fn AdditivePrimes( n as NSUInteger )
|
||||
NSUInteger i, s = 0, counter = 0
|
||||
|
||||
printf @"Additive Primes:"
|
||||
for i = 2 to n
|
||||
if ( fn IsPrime(i) ) and ( fn IsPrime( fn DigSum(i) ) )
|
||||
s++
|
||||
printf @"%4ld \b", i : counter++
|
||||
if counter == 10 then counter = 0 : print
|
||||
end if
|
||||
next
|
||||
printf @"\n\nFound %lu additive primes less than %lu.", s, n
|
||||
end fn
|
||||
|
||||
fn AdditivePrimes( 500 )
|
||||
|
||||
HandleEvents
|
||||
Loading…
Add table
Add a link
Reference in a new issue