33 lines
596 B
Plaintext
33 lines
596 B
Plaintext
p = 2
|
|
dp = 1
|
|
cont = 0
|
|
print("Primeros 19 primos circulares:")
|
|
while cont < 19
|
|
if isCircularPrime(p) then print p;" "; : cont += 1
|
|
p += dp
|
|
dp = 2
|
|
end while
|
|
end
|
|
|
|
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 isCircularPrime(p)
|
|
n = floor(log(p)/log(10))
|
|
m = 10^n
|
|
q = p
|
|
for i = 0 to n
|
|
if (q < p or not isPrime(q)) then return false
|
|
q = (q mod m) * 10 + floor(q / m)
|
|
next i
|
|
return true
|
|
end function
|