#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2 * 1e7 + 5, INF = (int)1e9 * 2 + 10;
const int TSH = 100;
bool is_prime(int p) {
  for (int i = 2; i * i <= p; i++)
    if (p % i == 0) return false;
  return true;
}
bool OFlow(long long a, long long b) {
  if ((INF + b - 1) / b <= a) return true;
  long long res = a * b, nb = res / a;
  return b != nb;
}
vector<int> P;
int cnt, m;
long long val, ans;
void dp(int n, int i) {
  if (i == m) {
    ans += (long long)(n / val) * (cnt % 2 ? -1 : 1);
    return;
  }
  dp(n, i + 1);
  if (!OFlow(val, P[i])) {
    val *= P[i];
    cnt++;
    dp(n, i + 1);
    val /= P[i];
    cnt--;
  }
}
int bymask(int n, int p) {
  while (P.back() >= p) P.pop_back();
  cnt = 0;
  m = ((int)P.size());
  ans = 0;
  val = p;
  dp(n, 0);
  assert(ans < INF);
  return ans;
}
bitset<MAXN> S;
int bysieve(int n, int p) {
  S = 0;
  n /= p;
  for (int i = 2; i < p; i++)
    if (!S[i]) {
      S[i] = 1;
      if ((long long)i * i < MAXN)
        for (int j = i * i; j < MAXN; j += i) S[j] = 1;
    }
  int ans = 0;
  for (int i = (1); i < (int)(n + 1); i++)
    if (!S[i]) ans++;
  return ans;
}
int countme(int n, int p) {
  if (p == 2) return n / p;
  if ((long long)p * p > n) return p <= n;
  if (p < TSH) return bymask(n, p);
  return bysieve(n, p);
}
int main() {
  for (int i = (2); i < (int)(TSH); i++)
    if (is_prime(i)) P.push_back(i);
  int l, r, p;
  while (scanf("%d %d %d", &l, &r, &p) >= 1) {
    if (is_prime(p)) {
      printf("%d\n", countme(r, p) - countme(l - 1, p));
    } else
      printf("0\n");
  }
  return 0;
}
