#include <bits/stdc++.h>
using namespace std;
const int mp = 2440000;
int primes[mp], top = 0;
long long a, b, k;
unsigned int prime[30000007 / 64 + 5];
void sieve() {
  memset(prime, -1, sizeof(prime));
  unsigned int i;
  unsigned int sqrtN = (unsigned int)sqrt((double)30000007) + 1;
  for (i = 3; i < sqrtN; i += 2)
    if ((i == 2 || ((i & 1) && prime[i >> 6] & (1 << ((i >> 1) & 31))))) {
      unsigned int i2 = i + i;
      for (unsigned int j = i * i; j < 30000007; j += i2)
        (prime[j >> 6] &= ~(1 << ((j >> 1) & 31)));
    }
}
bool forans[30000007];
void go(long long cur, int last) {
  if (cur > b) return;
  forans[cur] = 1;
  for (int i = last; i < top; i++) {
    long long v = cur * primes[i];
    if (v > b) return;
    go(v, i);
  }
}
bool isprime(long long n) {
  for (long long i = 2; i * i <= n; i++)
    if (n % i == 0) return 0;
  return 1;
}
int main() {
  cin >> a >> b >> k;
  a = (a + k - 1) / k, b = b / k;
  if (k > 50000) {
    bool r = isprime(k);
    if (r == 0) {
      cout << "0" << endl;
      return 0;
    }
    if (a <= 1 && b >= 1) {
      cout << "1" << endl;
      return 0;
    } else {
      cout << "0" << endl;
      return 0;
    }
  }
  sieve();
  if (!(k == 2 || ((k & 1) && prime[k >> 6] & (1 << ((k >> 1) & 31))))) {
    cout << "0" << endl;
    return 0;
  }
  for (int i = 2; i < 30000007; i++)
    if ((i == 2 || ((i & 1) && prime[i >> 6] & (1 << ((i >> 1) & 31)))))
      primes[top++] = i;
  if (k < 72) {
    vector<int> v;
    for (int i = 0; i < top; i++) {
      if (primes[i] >= k) break;
      v.push_back(primes[i]);
    }
    int n = v.size();
    long long ans = 0;
    for (int mask = 0; mask < (1 << n); mask++) {
      long long den = 1;
      for (int j = 0; j < n; j++)
        if ((((mask) >> (j)) & 1LL)) {
          den *= v[j];
          if (den >= b + 1) den = b + 1;
        }
      long long todo = b / den - (a + den - 1) / den + 1;
      int par = 0;
      for (int j = 0; j < n; j++)
        if ((((mask) >> (j)) & 1LL)) par = 1 - par;
      ans += (1 - 2 * par) * todo;
    }
    cout << ans << endl;
  } else {
    int j = 0;
    for (; primes[j] < k; j++)
      ;
    go(1, j);
    long long ans = 0;
    for (int i = a; i < b + 1; i++) ans += forans[i];
    cout << ans << endl;
  }
  return 0;
}
