-
Notifications
You must be signed in to change notification settings - Fork 0
/
loj1197.cpp
130 lines (105 loc) · 2.6 KB
/
loj1197.cpp
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
Author: Golam Rahman Tushar
........Aust Cse 27th batch.........
*/
//{ Template
//{ C-headers
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <cctype>
#include <cassert>
#include <ctime>
//}
//{ C++-headers
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
using namespace std;
//}
//}
//{ Floating-points
#define EPS DBL_EPSILON
#define abs(x) (((x) < 0) ? - (x) : (x))
#define zero(x) (abs (x) < EPS)
#define equal(a,b) (zero ((a) - (b)))
#define PI 2 * acos (0.0)
//}
#define INF 1<<29
#define ll long long
#define N 50000
template <typename T>
std::string to_string(T const& value) {
stringstream sstr;
sstr << value;
return sstr.str();
}
//}
template <class T> T gcd(T a,T b){if(b==0) return a;else return gcd(b,a%b);}
template <class T> T lcm(T a,T b){return (a*b)/gcd(a,b);}
template <class T> T power( T a, T b){if(b==0) return 1; T x=a;for(T i=2;i<=b;i++) a=a*x;return a;}
template <class T> T BigMod(T a,T b,T c){if(a==0) return 0;if(b==0) return 1;if(b%2==0){T x=BigMod(a,b/2,c)%c;return (x*x)%c;}else return ((a%c)*BigMod(a,b-1,c)%c)%c;}
bool prime[N];
vector<int>primes;
void sieve()
{
ll i,j,sq=sqrt(N);
prime[0]=prime[1]=true;
primes.push_back(2);
for(i=4;i<N;i+=2)
prime[i]=true;
for(i=3;i<=sq;i+=2)
{
if(prime[i]==false)
{
primes.push_back(i);
for(j=i*i;j<N;j+=2*i)
prime[j]=true;
}
}
while(i<N)
{
if(prime[i]==false)
primes.push_back(i);
i+=2;
}
}
bool com[100000+7];
int main ()
{
sieve();
ll t, a, b, i, sz = primes.size(), Case = 1;
scanf("%lld",&t);
while(t--) {
scanf("%lld %lld",&a, &b);
ll sq = sqrt(b), temp;
for(i=0;i<=b-a;i++) com[i] = 1;
for(i=0;i<sz&&primes[i]<=sq;i++) {
temp = (a/primes[i])*primes[i];
while(temp<=b) {
if((temp>primes[i])&&temp>=a) com[temp-a] = 0;
temp+=primes[i];
// if(primes[i]==2) temp+=primes[i];
// else temp+=(2*primes[i]);
}
}
ll cnt = 0;
for(i=0;i<=b-a;i++) {
if(com[i]) cnt++;
}
if(a==1) cnt--;
printf("Case %lld: %lld\n",Case++,cnt);
}
return 0;
}