-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path22.cpp
More file actions
41 lines (37 loc) · 745 Bytes
/
22.cpp
File metadata and controls
41 lines (37 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//https://dimikoj.com/problems/22/prime-number-by
#include<bits/stdc++.h>
using namespace std;
#define size 100001
char ara[size];
void sieve()
{
int i, j, root;
for (i = 2; i < size; i++)
ara[i] = 1;
root = sqrt (size);
for (i = 2; i <= root; i++) {
if (ara[i] == 1) {
for (j = i; i * j <= size; j++)
ara[i * j] = 0;
}
}
}
int main()
{
ios_base::sync_with_stdio (0);
cin.tie (0);
cout.tie (0);
int t, a, b, i, count;
sieve();
cin >> t;
while (t--) {
count = 0;
cin >> a >> b;
for (i = a; i <= b; i++) {
if (ara[i])
count++;
}
cout << count << "\n";
}
return 0;
}