#include <bits/stdc++.h>
using namespace std;
long long a, b, k, s, res;
vector<long long> P;
long long F(long long t) { return (b / t) - ((a - 1) / t); }
void G(long long p, bool ok, int c) {
  if (c == P.size()) return;
  if (p * P[c] <= b) {
    G(p, ok, c + 1);
    if (ok)
      res -= F(p * P[c]);
    else
      res += F(p * P[c]);
    G(p * P[c], !ok, c + 1);
  }
}
bool isPrime(int x) {
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0) return false;
  return true;
}
int main() {
  cin >> a >> b >> k;
  if (!isPrime(k)) {
    cout << 0 << endl;
    return 0;
  }
  if (k * k > b) {
    if (k >= a && k <= b)
      cout << 1 << endl;
    else
      cout << 0 << endl;
    return 0;
  }
  for (int i = 2; i < k; i++) {
    bool prime = true;
    for (int j = 2; j * j <= i; j++)
      if (i % j == 0) prime = false;
    if (prime) P.push_back(i);
  }
  res = F(k);
  G(k, true, 0);
  cout << res << endl;
  return 0;
}
