31 lines
565 B
Text
31 lines
565 B
Text
function isPrime(v)
|
|
if v < 2 then return False
|
|
if v mod 2 = 0 then return v = 2
|
|
if v mod 3 = 0 then return v = 3
|
|
d = 5
|
|
while d * d <= v
|
|
if v mod d = 0 then return False else d += 2
|
|
end while
|
|
return True
|
|
end function
|
|
|
|
function paresDePrimos(limite)
|
|
p1 = 0
|
|
p2 = 1
|
|
p3 = 1
|
|
cont = 0
|
|
for i = 5 to limite
|
|
p3 = p2
|
|
p2 = p1
|
|
p1 = isPrime(i)
|
|
if (p3 and p1) then cont += 1
|
|
next i
|
|
return cont
|
|
end function
|
|
|
|
n = 1
|
|
for i = 1 to 6
|
|
n = n * 10
|
|
print "pares de primos gemelos por debajo de < "; n; " : "; paresDePrimos(n)
|
|
next i
|
|
end
|