i wrote this super simple python code to count the number of prime numbers up to some large value. The problem is for a value like 1e+8
the program takes so much time, i want to improve this code for faster result and better performance.
here's the code:
import math
def is_prime(num):
if num%2 ==0 and num>2:
return 0
for i in range(3, int(math.sqrt(num)) + 1, 2):
if num % i == 0:
return 0
return 1
def count_prime(num):
ct=0;
for i in range(2,num+1,1):
if is_prime(i)==1:
ct+=1
return ct