def é_primo(x):
fator = 2
while fator * fator <= x:
if x % fator == 0:
return False
fator = fator + 1
return True
def n_primos(n):
contagem_primos = 0
for i in range(2, n + 1):
if é_primo(i):
contagem_primos = contagem_primos + 1
return contagem_primos
# Teste
for t in range(0, 100):
print("p(" + str(t) + ") = " + str(n_primos(t)))
ZGVmIMOpX3ByaW1vKHgpOgogICAgZmF0b3IgPSAyCiAgICB3aGlsZSBmYXRvciAqIGZhdG9yIDw9IHg6CiAgICAgICAgaWYgeCAlIGZhdG9yID09IDA6CiAgICAgICAgICAgIHJldHVybiBGYWxzZQogICAgICAgIGZhdG9yID0gZmF0b3IgKyAxCiAgICByZXR1cm4gVHJ1ZQoKZGVmIG5fcHJpbW9zKG4pOgogICAgY29udGFnZW1fcHJpbW9zID0gMAogICAgZm9yIGkgaW4gcmFuZ2UoMiwgbiArIDEpOgogICAgICAgIGlmIMOpX3ByaW1vKGkpOgogICAgICAgICAgICBjb250YWdlbV9wcmltb3MgPSBjb250YWdlbV9wcmltb3MgKyAxCiAgICByZXR1cm4gY29udGFnZW1fcHJpbW9zCgojIFRlc3RlCmZvciB0IGluIHJhbmdlKDAsIDEwMCk6CiAgICBwcmludCgicCgiICsgc3RyKHQpICsgIikgPSAiICsgc3RyKG5fcHJpbW9zKHQpKSk=