import math # Returns True if n is a prime; False otherwise def isPrime(n): factor = 2 # initial value of possible factor factorUpperBound = math.sqrt(n) # the largest possible factor we need to test is sqrt(n) # loop to generate and test all possible factors while (factor <= factorUpperBound): # test if n is evenly divisible by factor if (n % factor == 0): return False factor = factor + 1 return True # Returns the number of prime numbers less than or equal to N def numPrimes(N): count = 0 while N > 1: if isPrime(N): count = count + 1 N = N - 1 return count