Prime numbers which contain 123: Difference between revisions

Initial FutureBasic task solution added
No edit summary
(Initial FutureBasic task solution added)
Line 432:
 
Encontrados 451 números primos por debajo de 1000000
</pre>
 
 
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
local fn IsPrime( n as long ) as BOOL
long i
BOOL result = YES
if ( n < 2 ) then result = NO : exit fn
for i = 2 to n + 1
if ( i * i <= n ) and ( n mod i == 0 )
result = NO : exit fn
end if
next
end fn = result
 
 
local fn PrimeWith123( limit as long )
long i, column = 1
CFStringRef numStr
NSLog( @"Prime numbers less than 100,000 which contain '123':\n" )
for i = 1 to limit
numStr = fn StringWithFormat( @"%lu", i )
if ( fn IsPrime( i ) ) and ( fn StringContainsString( numStr, @"123" ) )
NSLog( @"%-6lu\b", i )
if column == 10 then column = 0 : NSLog( @"" )
column++
end if
next
end fn
 
fn PrimeWith123( 100000 )
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
Prime numbers less than 100,000 which contain '123':
 
12373 12377 12379 12391 17123 20123 22123 28123 29123 31123
31231 31237 34123 37123 40123 41231 41233 44123 47123 49123
50123 51239 56123 59123 61231 64123 65123 70123 71233 71237
76123 81233 81239 89123 91237 98123
</pre>
 
715

edits