#include <bits/stdc++.h>
using namespace std;
vector<bool> prime;
const int maxN = 100500;
int p[maxN];
long long as;
void init() {
  int zzz = maxN;
  prime.resize(zzz, true);
  for (int i = 2; i < zzz; i++) {
    if (prime[i]) {
      for (int j = i * 2; j < zzz; j += i) {
        prime[j] = false;
      }
    }
  }
}
void rec(int d, int num, int s, int start, int len) {
  as += d * (s / num);
  for (int i = start; i < len; i++) {
    long long x = num;
    x *= p[i];
    if (x > s) {
      return;
    }
    rec(-d, num * p[i], s, i + 1, len);
  }
}
int f(int b, int k) {
  int s = b / k;
  if (s == 0) {
    return 0;
  }
  if (k > 1e5) {
    return 1;
  } else {
    int len = 0;
    for (int i = 2; i < k; i++) {
      if (!prime[i]) continue;
      p[len++] = i;
    }
    as = 0;
    rec(1, 1, s, 0, len);
    return (int)as;
  }
}
int main() {
  init();
  int a, b, k;
  cin >> a >> b >> k;
  bool isp = true;
  for (int i = 2; i * i <= k; i++) {
    if (k % i == 0) {
      isp = false;
    }
  }
  if (!isp) {
    printf("0");
    return 0;
  }
  cout << (int)f(b, k) - f(a - 1, k) << endl;
  return 0;
}
