Skip to content

Instantly share code, notes, and snippets.

@solen003
Created August 6, 2018 20:56
Show Gist options
  • Save solen003/6ecf32b45ad541609a72d1edc0b77551 to your computer and use it in GitHub Desktop.
Save solen003/6ecf32b45ad541609a72d1edc0b77551 to your computer and use it in GitHub Desktop.
prime counter
def count_primes(n):
import math
primes_count = 0
for i in range(1, n+1, 2):
if i == 1:
pass
if i == 2:
primes_count += 1
elif i%2 == 0:
continue
else:
for x in range(3, int(i**0.5)+1, 2):
if i%x == 0:
break
else:
primes_count += 1
print(primes_count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment