Neighbour primes: Difference between revisions

Initial FutureBasic task solution added
(Initial FutureBasic task solution added)
Line 661:
487 491 239119
</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
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
 
 
local fn FindNeighborPrimes( searchLimit as long )
NSUInteger p, q
printf @"p q p*q+2"
printf @"----------------------"
for p = 2 to searchLimit
if ( fn IsPrime(p) == NO ) then continue
q = p + 1
while ( fn IsPrime(q) == NO )
q += 1
wend
if ( fn IsPrime( p * q + 2 ) == NO ) then continue
printf @"%lu\t\t%-6lu\t%-6lu", p, q, p * q + 2
next
end fn
 
fn FindNeighborPrimes( 499 )
 
NSLog( @"%@", fn WindowPrintViewString( 1 ) )
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre style="height:20ex;">
p q p*q+2
----------------------
3 5 17
5 7 37
7 11 79
13 17 223
19 23 439
67 71 4759
149 151 22501
179 181 32401
229 233 53359
239 241 57601
241 251 60493
269 271 72901
277 281 77839
307 311 95479
313 317 99223
397 401 159199
401 409 164011
419 421 176401
439 443 194479
487 491 239119
 
</pre>
 
 
=={{header|Fōrmulæ}}==
715

edits