Primes which contain only one odd digit: Difference between revisions
Content added Content deleted
m (→stretch: all prior digits even comment) |
(add FreeBASIC) |
||
Line 230: | Line 230: | ||
202635 |
202635 |
||
</pre> |
</pre> |
||
=={{header|FreeBASIC}}== |
|||
<lang freebasic> |
|||
#include "isprime.bas" |
|||
function b(j as uinteger, n as uinteger) as uinteger |
|||
'auxiliary function for evendig below |
|||
dim as uinteger m = int(log(n-1)/log(5)) |
|||
return int((n-1-5^m)/5^j) |
|||
end function |
|||
function evendig(n as uinteger) as uinteger |
|||
'produces the integers with only even digits |
|||
dim as uinteger m = int(log(n-1)/log(5)), a |
|||
a = ((2*b(m, n)) mod 8 + 2)*10^m |
|||
if n<=1 or m=0 then return a |
|||
for j as uinteger = 0 to m-1 |
|||
a += ((2*b(j, n)) mod 10)*10^j |
|||
next j |
|||
return a |
|||
end function |
|||
dim as uinteger n=1, count = 0, p=1 |
|||
while p<1000000 |
|||
p = 1 + evendig(n) 'if it's a prime the odd digit must be the last one |
|||
if isprime(p) then |
|||
count += 1 |
|||
if p<1000 then print p |
|||
end if |
|||
n+=1 |
|||
wend |
|||
print "There are ";count;" such primes below one million."</lang> |
|||
=={{header|Go}}== |
=={{header|Go}}== |