#include <bits/stdc++.h>
using namespace std;
const int MAXN = (1 << 20);
const int bound = (int)4e7 + 42;
int64_t L, R, k;
void read() { cin >> L >> R >> k; }
bool is_prime(int64_t x) {
  for (int64_t d = 2; d * d <= x; d++)
    if (x % d == 0) return false;
  return true;
}
int lp[bound + 42];
int64_t in_ex(int64_t N) {
  vector<int64_t> p;
  for (int i = 2; i < k; i++)
    if (is_prime(i)) p.push_back(i);
  int sz = p.size();
  int64_t ans = 0;
  for (int mask = 0; mask < (1 << sz); mask++) {
    int64_t d = 1;
    for (int i = 0; i < sz; i++)
      if ((mask >> i) & 1) d *= p[i];
    if (__builtin_popcount(mask) & 1)
      ans -= ((N / k) / d);
    else
      ans += ((N / k) / d);
  }
  return ans;
}
int64_t f(int64_t N) {
  if (N / k >= bound) return in_ex(N);
  int64_t ans = (N >= k);
  for (int d = k; d * k <= N; d++)
    if (lp[d] >= k) ans++;
  return ans;
}
void precompute() {
  for (int64_t d = 2; d <= bound; d++)
    if (!lp[d]) {
      lp[d] = d;
      for (int64_t j = d * d; j <= bound; j += d)
        if (!lp[j]) lp[j] = d;
    }
}
void solve() {
  precompute();
  if (!is_prime(k)) {
    cout << 0 << '\n';
    return;
  }
  cout << f(R) - f(L - 1) << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  read();
  solve();
  return 0;
}
