#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int parent[N];
bool isComposite[N];
void init(int n) {
for (int i = 0; i <= n; i++) {
parent[i] = i;
}
}
int find(int x) {
if (x == parent[x]) return x;
return parent[x] = find(parent[x]);
}
void unionSet(int x, int y) {
int rootX = find(x);
int rootY = find(y);
if (rootX != rootY) {
parent[rootY] = rootX;
}
}
void sieve(int n) {
for (int i = 2; i <= n; i++) {
if (!isComposite[i]) {
for (int j = i * i; j <= n; j += i) {
isComposite[j] = true;
}
}
}
}
bool hasCommonFactor(int x, int y, int p) {
for (int i = min(x, y); i >= p; i--) {
if (!isComposite[i] && x % i == 0 && y % i == 0) {
return true;
}
}
return false;
}
int main() {
int a, b, p;
cin >> a >> b >> p;
init(b);
sieve(b);
for (int i = a; i < b; i++) {
for (int j = i + 1; j <= b; j++) {
if (hasCommonFactor(i, j, p)) {
unionSet(i, j);
}
}
}
int ans = 0;
for (int i = a; i <= b; i++) {
if (parent[i] == i) {
ans++;
}
}
cout << ans << endl;
return 0;
}