-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1016.cpp
42 lines (36 loc) · 897 Bytes
/
1016.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
#include <bits/stdc++.h>
#define swap(a,b) (a)^=(b)^=(a)^=(b)
#define endl '\n'
using namespace std;
typedef long long lld;
int main()
{
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
vector<bool> prime_check(1000005, false);
prime_check[0] = prime_check[1] = true;
lld mn, mx;
cin>>mn>>mx;
vector<bool> v(mx-mn+1, false);
vector<lld> prime_number;
for(lld i=2;i<=1000000;i++)
{
if(prime_check[i]) continue;
prime_number.push_back(i*i);
for(int j=i+i;j<=1000000;j+=i)
prime_check[j] = true;
}
for(size_t i=0;i<prime_number.size();i++)
{
lld check_point = (mn / prime_number[i]+1) * prime_number[i];
if(mn % prime_number[i]==0) check_point = mn;
for(lld j=check_point;j<=mx;j+=prime_number[i])
v[mx-j] = true;
}
int cnt = 0;
for(size_t i=0;i<v.size();i++)
if(!v[i]) cnt++;
cout<<cnt;
return 0;
}