#include <bits/stdc++.h>
using namespace std;
int t = 2e9;
bool vis[100000];
int primeList[100000], sz;
void init() {
  for (int i = 2; i < 100000; ++i) {
    if (!vis[i]) {
      primeList[sz++] = i;
      for (int j = i; j < 100000; j += i) {
        vis[j] = true;
      }
    }
  }
}
int lim;
int solve2(int p, int ind, int cur) {
  if (p >= ind) {
    return 0;
  }
  if (lim < abs((long long)cur * primeList[p])) {
    return 0;
  }
  int ret = solve2(p + 1, ind, cur);
  cur *= -primeList[p];
  ret += lim / cur;
  ret += solve2(p + 1, ind, cur);
  return ret;
}
int bruteForce(int n, int k) {
  if (n == 0) {
    return 0;
  }
  if (n < k) {
    return 1;
  }
  if (n == k) {
    return 2;
  }
  int p = -1;
  for (int i = 0; i < sz; ++i) {
    if (primeList[i] == k) {
      p = i;
      break;
    }
  }
  assert(p != -1);
  int ret = n;
  lim = n;
  for (int i = 0; i < p; ++i) {
    int cur = -primeList[i];
    ret += n / cur;
    ret += solve2(i + 1, p, cur);
  }
  return ret;
}
void solve() {
  int a, b, k;
  scanf("%d %d %d ", &a, &b, &k);
  for (int i = 2; i * i <= k; ++i) {
    if (k % i == 0) {
      printf("0\n");
      return;
    }
  }
  int ret = bruteForce(b / k, k) - bruteForce((a - 1) / k, k);
  printf("%d\n", ret);
}
int main() {
  init();
  solve();
  return 0;
}
