Skip to content
Snippets Groups Projects
Commit 7bf068dc authored by Miguel Stiven Ascanio Quinchia's avatar Miguel Stiven Ascanio Quinchia
Browse files

Números primos (Miguel Ascanio)

parent f93bcc81
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:bfa85485-9b76-43ac-97cf-6225e214984d tags:
# Numeros primos
%% Cell type:code id:e5f256cd-f786-42fa-acc6-fd839023e168 tags:
``` python
import numpy as np
import matplotlib.pyplot as plt
```
%% Cell type:code id:e9797f5a-68b1-42ee-9e50-3262626fd5d2 tags:
``` python
N = 20
numeros = np.arange(2, N+1)
primos = [numeros[0]]
for i in np.arange(1, len(numeros)):
for j in np.arange(0, i):
cond = numeros[i]%numeros[j]
if cond == 0:
break
if cond!=0:
primos.append(numeros[i])
```
%% Cell type:code id:4a712079-9eb1-4f10-ba4b-09a57927ca2c tags:
``` python
def numeros_primos_func(N):
numeros = np.arange(2, N+1)
primos = [numeros[0]]
for i in np.arange(1, len(numeros)):
for j in np.arange(0, i):
cond = numeros[i]%numeros[j]
if cond == 0:
break
if cond!=0:
#print(numeros[i])
primos.append(numeros[i])
return primos
def contador_primos(N):
numprim = numeros_primos_func(N)
return len(numprim)
```
%% Cell type:code id:68a92cec-dd52-4d68-8c63-b92d7f1ed74e tags:
``` python
numeros_primos_func(71)
```
%% Output
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]
%% Cell type:code id:a40ace4c-895c-409c-b1d5-265ae33f1fb8 tags:
``` python
contador_primos(71)
```
%% Output
20
%% Cell type:code id:8db8f495-627a-416c-ab55-d2a065a48b2d tags:
``` python
mis_numeros = np.arange(2, 1000)
primos_por_rango = []
for r in mis_numeros:
cantidad_primos = contador_primos(r)
primos_por_rango.append(cantidad_primos)
plt.figure(figsize=(20,20))
plt.plot(mis_numeros, primos_por_rango, "k.")
plt.xlabel('Rango de números')
plt.ylabel('Cantidad de números primos')
plt.title('Números primos hasta 1000')
plt.show()
```
%% Output
%% Cell type:code id:0ec25533-53f7-48be-8c79-a7f946cfc032 tags:
``` python
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment