给定一个区间以内,求其中素数的个数,采用C语言方式的实现

Problem Description
Easy question! Calculate how many primes between [1...n]!

Input
Each line contain one integer n(1 <= n <= 1e11).Process to end of file.

Output
For each case, output the number of primes in interval [1...n]

Sample Input
2
3
10

Sample Output
1
2
4

#include <stdio.h>
#include<math.h>


bool isPrime(long num)
{
    long i = 2;
    if(num <= 1)
    {
        return false;
    }

    long sqrNum = sqrt(num);

    for(i = 2; i <= sqrNum; i++)
    {
        if(num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int getPrimeCount(long a)
{
    int sum = 0;
    long start;

    if(a <= 1)
    {
        return 0;
    }

    for(start = 2; start <= a; start++)
    {
        if(isPrime(start))
        {
            sum++;
        }
    }
    return sum;
}

int main()
{
    long a;
    scanf("%ld", &a);
    printf("%d\n", getPrimeCount(a));
    return 0;
}