Factorial primes: Difference between revisions

Initial FutureBasic task solution added
(Initial FutureBasic task solution added)
Line 388:
31: 546!-1 -> 14130200926141832545..99999999999999999999 [1260 digits]
</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
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
</syntaxhighlight>
{{output}}
<pre>
First 10 factorial primes:
1: 1! + 1 = 2
2: 2! + 1 = 3
3: 3! - 1 = 5
4: 3! + 1 = 7
5: 4! - 1 = 23
6: 6! - 1 = 719
7: 7! - 1 = 5039
8: 11! + 1 = 39916801
9: 12! - 1 = 479001599
10: 14! - 1 = 87178291199
</pre>
 
 
=={{header|J}}==
715

edits