Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
41
Task/Factorial-primes/FutureBasic/factorial-primes.basic
Normal file
41
Task/Factorial-primes/FutureBasic/factorial-primes.basic
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
include "NSLog.incl"
|
||||
|
||||
local fn Factorial( n as NSUInteger ) as NSUInteger
|
||||
NSUInteger factorial = 1
|
||||
|
||||
if n > 1 then factorial = n * fn Factorial( n -1 )
|
||||
end fn = factorial
|
||||
|
||||
local fn IsPrime( n as NSUInteger ) as BOOL
|
||||
BOOL isPrime = YES
|
||||
NSUInteger i
|
||||
|
||||
if n < 2 then exit fn = NO
|
||||
if n = 2 then exit fn = YES
|
||||
if n mod 2 == 0 then exit fn = NO
|
||||
for i = 3 to int(n^.5) step 2
|
||||
if n mod i == 0 then exit fn = NO
|
||||
next
|
||||
end fn = isPrime
|
||||
|
||||
void local fn FactorialPrimes( n as long )
|
||||
NSUInteger found = 0, i = 1
|
||||
|
||||
NSLog( @"First %lu factorial primes:", n )
|
||||
while ( found < n )
|
||||
NSUInteger fct = fn Factorial( i )
|
||||
if ( fn IsPrime( fct - 1 ) )
|
||||
found++
|
||||
NSLog( @"%2lu: %3lu! - 1 = %-lu", found, i, fct - 1 )
|
||||
end if
|
||||
if ( fn IsPrime( fct + 1 ) )
|
||||
found++
|
||||
NSLog( @"%2lu: %3lu! + 1 = %-lu", found, i, fct + 1 )
|
||||
end if
|
||||
i++
|
||||
wend
|
||||
end fn
|
||||
|
||||
fn FactorialPrimes( 10 )
|
||||
|
||||
HandleEvents
|
||||
Loading…
Add table
Add a link
Reference in a new issue