#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int fa[100010], a, b, p, ans;
bool is_prime[100010];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]);}
void prepare() {
scanf("%d %d %d", &a, &b, &p);
for (register int i = a; i <= b; i ++)
fa[i] = i;
}
void solve() {
ans = b - a + 1;
for (register int i = 2; i <= b; i ++) {
if (!is_prime[i]) {
if (i >= p)
for (register int j = i * 2; j <= b; j += i) {
is_prime[j] = true;
if (j - i >= a && find(j) != find(j - i))
fa[find(j)] = find(j - i), ans --;
}
else for (register int j = i * 2; j <= b; j += i)
is_prime[j] = true;
}
}
printf("%d\n", ans);
}
int main() {
freopen("setb.in", "r", stdin);
freopen("setb.out", "w", stdout);
prepare();
solve();
return 0;
}