Emirp primes: Difference between revisions

Content added Content deleted
(Initial FutureBasic task solution added)
Line 1,364: Line 1,364:
10000th: 948349
10000th: 948349
</pre>
</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 ReverseNumber( n as NSUInteger ) as NSUInteger
NSInteger sum = 0
if n < 10 then exit fn = n
while ( n > 0 )
sum = 10 * sum + ( n mod 10 )
n /= 10
wend
end fn = sum


local fn IsEmirp( n as NSUInteger ) as BOOL
BOOL result = NO
NSUInteger r = fn ReverseNumber(n)
if r != n and fn IsPrime(n) and fn IsPrime(r) then result = YES
end fn = result


local fn GetEmirpPrimes
NSUInteger count = 0, i = 13
printf @"\nThe first 20 Emirp primes are:"
do
if fn IsEmirp(i) then printf @"%4lu\b", i : count++
i += 2
until ( count == 20 )
printf @"\n\nThe Emirp primes between 7700 and 8000 are:"
i = 7701
while ( i < 8000 )
if fn IsEmirp(i) then printf @"%5lu\b", i
i += 2
wend
i = 13 : count = 0
while (1)
if fn IsEmirp(i) then count++
if count = 10000 then exit while
i += 2
wend
printf @"\n\nThe 10,000th Emirp prime is: %lu", i
end fn

fn GetEmirpPrimes

HandleEvents
</syntaxhighlight>
{{output}}
<pre>
The first 20 Emirp primes are:
13 17 31 37 71 73 79 97 107 113 149 157 167 179 199 311 337 347 359 389

The Emirp primes between 7700 and 8000 are:
7717 7757 7817 7841 7867 7879 7901 7927 7949 7951 7963

The 10,000th Emirp prime is: 948349
</pre>



=={{header|Go}}==
=={{header|Go}}==