#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30) - 1;
const long double eps = 1e-9;
const long double pi = fabs(atan2(0.0, -1.0));
int a, b, k;
void Load() { cin >> a >> b >> k; }
inline bool isPrime(int a) {
  for (long long i = 2; ((i) * (i)) <= a; i++)
    if (a % i == 0) return false;
  return true;
}
vector<int> pr;
inline void generate(int n) {
  for (int i = 2; i <= n; i++)
    if (isPrime(i)) pr.push_back(i);
}
int count(int n, int j) {
  if (n < pr[j]) return 0;
  int res = n / pr[j];
  for (int i = j - 1; i >= 0; i--) res -= count(n / pr[j], i);
  return res;
}
inline int f(int x) {
  if (k > x) return 0;
  if ((((long long)k) * ((long long)k)) >= x) return 1;
  return count(x, (int)pr.size() - 1);
}
void Solve() {
  if (!isPrime(k)) {
    cout << 0;
    return;
  }
  if ((((long long)k) * ((long long)k)) < b) generate(k);
  cout << f(b) - f(a - 1);
}
int main() {
  Load();
  Solve();
  return 0;
}
