#include <bits/stdc++.h>
using namespace std;
const int N = 1000000 + 10;
bool flag[N];
int prime[80000];
int D[N];
void prime_gen_linear() {
  memset(flag, 0, sizeof(flag));
  int m = 0;
  for (int i = 2; i < N; ++i) {
    if (!flag[i]) {
      prime[m++] = i;
      D[i] = i;
    }
    for (int j = 0; j < m; ++j) {
      int k = prime[j] * i;
      if (k >= N) break;
      D[k] = prime[j];
      flag[k] = true;
      if (i % prime[j] == 0) break;
    }
  }
  D[1] = INT_MAX;
}
int bound, lim;
int total;
void search(int dep, int low, int cur) {
  if (cur > 1) {
    if (dep & 1)
      total -= bound / cur;
    else
      total += bound / cur;
  }
  for (int i = low; prime[i] < lim && cur * prime[i] <= bound; ++i)
    search(dep + 1, i + 1, cur * prime[i]);
}
int doit(int n, int p) {
  n /= p;
  if (n == 0) return 0;
  if (p > 2000) {
    int ret = 0;
    for (int i = 1; i <= n; ++i)
      if (D[i] >= p) ++ret;
    return ret;
  } else {
    bound = n;
    lim = p;
    total = n;
    search(0, 0, 1);
    return total;
  }
}
bool is_prime(int n) {
  if (n == 2) return true;
  if (n % 2 == 0) return false;
  for (int i = 3; i * i <= n; i += 2)
    if (n % i == 0) return false;
  return true;
}
int main() {
  prime_gen_linear();
  int A, B, K;
  scanf("%d %d %d", &A, &B, &K);
  if (!is_prime(K)) {
    puts("0");
    return 0;
  }
  printf("%d\n", doit(B, K) - doit(A - 1, K));
  return 0;
}
