#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const long long INF = 1LL << 61;
int a, b, k;
bool ok(int n) {
  int i;
  for (i = 2; i * i <= n; ++i)
    if (n % i == 0) return 0;
  return 1;
}
int ct(int n) {
  int i, j = 0;
  for (i = 2; i * i <= n; ++i)
    if (n % i == 0) {
      n /= i;
      ++j;
      if (n % i == 0) return 0;
    }
  if (n != 1) ++j;
  return j % 2 ? -1 : 1;
}
int gao(int n, int k);
int g(int n, int k) {
  int r = n, i;
  for (i = 2; i < k; ++i) r -= gao(n, i);
  return r;
}
int gao(int n, int k) {
  if (k > n || !ok(k)) return 0;
  if ((long long)k * k > n) return 1;
  return g(n / k, k);
}
int main() {
  while (cin >> a >> b >> k) {
    if (!ok(k))
      cout << 0 << endl;
    else {
      cout << gao(b, k) - gao(a - 1, k) << endl;
    }
  }
  return 0;
}
