fork download
  1. def é_primo(x):
  2. fator = 2
  3. while fator * fator <= x:
  4. if x % fator == 0:
  5. return False
  6. fator = fator + 1
  7. return True
  8.  
  9. def n_primos(n):
  10. contagem_primos = 0
  11. for i in range(2, n + 1):
  12. if é_primo(i):
  13. contagem_primos = contagem_primos + 1
  14. return contagem_primos
  15.  
  16. # Teste
  17. for t in range(0, 100):
  18. print("p(" + str(t) + ") = " + str(n_primos(t)))
Success #stdin #stdout 0.02s 28384KB
stdin
Standard input is empty
stdout
p(0) = 0
p(1) = 0
p(2) = 1
p(3) = 2
p(4) = 2
p(5) = 3
p(6) = 3
p(7) = 4
p(8) = 4
p(9) = 4
p(10) = 4
p(11) = 5
p(12) = 5
p(13) = 6
p(14) = 6
p(15) = 6
p(16) = 6
p(17) = 7
p(18) = 7
p(19) = 8
p(20) = 8
p(21) = 8
p(22) = 8
p(23) = 9
p(24) = 9
p(25) = 9
p(26) = 9
p(27) = 9
p(28) = 9
p(29) = 10
p(30) = 10
p(31) = 11
p(32) = 11
p(33) = 11
p(34) = 11
p(35) = 11
p(36) = 11
p(37) = 12
p(38) = 12
p(39) = 12
p(40) = 12
p(41) = 13
p(42) = 13
p(43) = 14
p(44) = 14
p(45) = 14
p(46) = 14
p(47) = 15
p(48) = 15
p(49) = 15
p(50) = 15
p(51) = 15
p(52) = 15
p(53) = 16
p(54) = 16
p(55) = 16
p(56) = 16
p(57) = 16
p(58) = 16
p(59) = 17
p(60) = 17
p(61) = 18
p(62) = 18
p(63) = 18
p(64) = 18
p(65) = 18
p(66) = 18
p(67) = 19
p(68) = 19
p(69) = 19
p(70) = 19
p(71) = 20
p(72) = 20
p(73) = 21
p(74) = 21
p(75) = 21
p(76) = 21
p(77) = 21
p(78) = 21
p(79) = 22
p(80) = 22
p(81) = 22
p(82) = 22
p(83) = 23
p(84) = 23
p(85) = 23
p(86) = 23
p(87) = 23
p(88) = 23
p(89) = 24
p(90) = 24
p(91) = 24
p(92) = 24
p(93) = 24
p(94) = 24
p(95) = 24
p(96) = 24
p(97) = 25
p(98) = 25
p(99) = 25