#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6 + 2;
const long long MAXM = 24285720;
bool p[MAXN];
vector<long long> primes;
long long cntdivs[MAXN];
int mindiv[MAXM];
void eratosten() {
  for (long long i = 2; i < MAXN; ++i) {
    if (p[i] == 0) {
      if (i < 80) primes.push_back(i);
      for (long long j = 2 * i; j < MAXN; j += i) {
        p[j] = 1;
      }
      mindiv[i] = i;
      for (long long j = i * i; j < MAXM; j += i) {
        if (mindiv[j] == 0) mindiv[j] = i;
      }
    }
  }
}
long long s(long long x, long long k) {
  if (k < 80) {
    long long number;
    long long ret = 0;
    for (long long i = 0; i < primes.size(); ++i) {
      if (primes[i] == k) number = i;
    }
    for (long long mask = 1; mask < (1 << (number + 1)); ++mask) {
      if (!(mask & (1 << number))) continue;
      long long cnt = 0;
      long long nok = 1;
      bool overflow = 0;
      for (long long l = 0; l < primes.size(); l++) {
        if (mask & (1 << l)) {
          if (l < number) cnt++;
          if (nok * primes[l] > x) overflow = 1;
          nok *= primes[l];
        }
      }
      if (overflow) continue;
      if (cnt % 2 == 0)
        ret += x / nok;
      else
        ret -= x / nok;
    }
    return ret;
  } else {
    long long ret = 0;
    for (long long i = k; i <= x; i += k) {
      long long t = i / k;
      if (mindiv[t] == 0 || mindiv[t] >= k) {
        ++ret;
      }
    }
    return ret;
  }
}
int main() {
  eratosten();
  for (long long i = 1; i < MAXN; ++i) {
    for (long long j = i; j < MAXN; j += i) {
      ++cntdivs[j];
    }
  }
  long long a, b, k;
  cin >> a >> b >> k;
  for (long long i = 2; i * i <= k; ++i) {
    if (k % i == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  cout << s(b, k) - s(a - 1, k) << endl;
  return 0;
}
