View Code of Problem 103

#include <cctype>
#include <iostream>
#include <stack>
#include<algorithm>
#include <vector>
using namespace std;

vector<int> primes;
int arr[1000001] = {0};
void findPrime()
{
    for (int i = 2; i < 1000001; i ++)
    {
        if (arr[i] == 0)
        {
            primes.push_back(i);
            for (int j = i + i; j < 1000001;j+=i)
                arr[j] = 1;
        }
    }
}

int main(void)
{
    int a, b;
    arr[1] = 1;
    findPrime();
    while (cin >> a >> b)
    {
        auto t1 = lower_bound(primes.begin(), primes.end(), a);
        auto t2 = upper_bound(primes.begin(), primes.end(), b);
        cout << distance(t1, t2) << endl;
    }
}

Double click to view unformatted code.


Back to problem 103