#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:60777216")
using namespace std;
long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); }
string filename = "test";
bool p[100000];
vector<int> primes;
bool test_prime(int n) {
  if (n < 100000) return !p[n];
  for (int _n(primes.size()), i(0); i < _n; i++) {
    if (n % primes[i] == 0) return false;
    long long pp = primes[i];
    if (pp * pp > n) break;
  }
  return true;
}
int go(int a, int k);
int go1(int a, int k) {
  if (a == 0) return 0;
  if (!test_prime(k)) return go1(a, k - 1);
  int ret = 0;
  for (int i = 0; primes[i] <= k; ++i) ret += go(a, primes[i]);
  return ret;
}
int go(int a, int k) {
  if (!test_prime(k)) return 0;
  if (a == 0) return 0;
  return a / k - go1(a / k, k - 1);
}
int main() {
  memset(p, false, sizeof(p));
  for (int i = 2; i < 100000; ++i) {
    if (!p[i]) {
      primes.push_back(i);
      for (int j = 2 * i; j < 100000; j += i) {
        p[j] = true;
      }
    }
  }
  int a, b, k;
  scanf("%d %d %d", &a, &b, &k);
  int res = 0;
  if (k >= 100000) {
    res = test_prime(k) && a <= k && k <= b ? 1 : 0;
  } else {
    res = go(b, k) - go(a - 1, k);
  }
  printf("%d\n", res);
  return 0;
}
