#include <bits/stdc++.h>
using namespace std;
bool isPrime(int x) {
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) return false;
  }
  return true;
}
int sm[100007];
vector<int> pr;
int BUBEN;
int calc(int n, int k) {
  if (n <= BUBEN) {
    int res = 0;
    for (int i = 1; i <= n; i++) {
      if (sm[i] == k) res++;
    }
    return res;
  }
  int res = n / k;
  for (int i = 0; i < (int)pr.size(); i++) {
    if (pr[i] < k && pr[i] <= n / k) {
      res -= calc(n / k, pr[i]);
    }
  }
  return res;
}
int main() {
  int a, b, k;
  scanf("%d %d %d", &a, &b, &k);
  if (!isPrime(k)) {
    puts("0");
    return 0;
  }
  BUBEN = sqrt(b);
  for (int i = 2; i <= BUBEN; i++) {
    if (isPrime(i)) {
      pr.push_back(i);
    }
    for (int j = i; j <= BUBEN; j += i) {
      if (sm[j] == 0) sm[j] = i;
    }
  }
  int res = calc(b, k) - calc((a - 1), k);
  printf("%d\n", res);
}
