#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define PII pair<int,int >
#define int long long
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1e6+10;
int a,b,p;
int a1,b1;
int acc[N];
int vis[N],pri[N],cnt;
void init(int x)
{
for(int i=2;i<=x;i++)
{
if(vis[i]==0) pri[++cnt] = i;
for(int j=1;j<=cnt;j++)
{
if(pri[j]*i>x) break;
vis[i*pri[j]] = 1;
if(i%pri[j]==0) break;
}
}
}
int find(int x)
{
if(acc[x]==x) return x;
else return acc[x]=find(acc[x]);
}
signed main()
{
IOS;
init(1e5+5);
cin>>a>>b>>p;
for(int i=a;i<=b;i++) acc[i]=i;
for(int i=1;i<=cnt;i++)
{
if(pri[i]<p) continue;
vector<int>v;
for(int j=1;;j++)
{
int x=pri[i]*j;
if(x>b) break;
if(x>=a&&x<=b) v.push_back(x);
}
for(int j=1;j<v.size();j++)
{
int a1=v[0],b1=v[j];
int t1=find(a1),t2=find(b1);
if(t1!=t2) acc[t1]=t2;
}
}
int sum=0;
for(int i=a;i<=b;i++)
{
if(i==find(i))
sum++;
}
cout<<sum;
return 0;
}
10-14
195
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-05
499
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-30
218
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-06