#include <bits/stdc++.h>
using namespace std;
int MAX;
int cnt;
int isit[30000005];
vector<int> prime;
void sieve(void) {
  for (int i = 2; i < 30000005; i++) {
    if (isit[i]) continue;
    prime.push_back(i);
    for (int j = i + i; j < 30000005; j += i) isit[j] = 1;
  }
}
void go(int now, long long x) {
  if (x * prime[now] > MAX) {
    cnt++;
    return;
  }
  if (now == prime.size()) {
    cnt++;
    return;
  }
  go(now + 1, x);
  while (true) {
    x *= prime[now];
    if (x > MAX) break;
    go(now + 1, x);
  }
}
bool isprime(int x) {
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0) return false;
  return true;
}
int func(int a, int k) {
  if (a < 2 || k > a) return 0;
  if (!isprime(k)) return 0;
  if (k > prime[20]) {
    if (k > 100000) return 1;
    MAX = a;
    for (int i = 0; i < prime.size(); i++) {
      if (prime[i] == k) {
        cnt = 0;
        go(i, k);
        return cnt;
      }
    }
  }
  int pos;
  for (pos = 0; pos < prime.size(); pos++)
    if (prime[pos] == k) break;
  int tot = 1 << pos, ret = 0;
  for (int i = 0; i < tot; i++) {
    long long tmp = k;
    int j;
    for (j = 0; j < pos; j++) {
      if (i & (1 << j)) {
        tmp *= prime[j];
        if (tmp > a) break;
      }
    }
    if (__builtin_popcount(i) % 2)
      ret -= (a / tmp);
    else
      ret += (a / tmp);
  }
  return ret;
}
int main() {
  sieve();
  int a, b, k;
  cin >> a >> b >> k;
  cout << func(b, k) - func(a - 1, k) << endl;
  return 0;
}
