#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
A convert(B x) {
  stringstream s;
  s << x;
  A r;
  s >> r;
  return r;
}
bool fl[40000];
vector<int> pr;
void out(int res) {
  cout << res << endl;
  exit(0);
}
bool isPrime(int n) {
  for (int i = (2), _b(n); i < _b; ++i) {
    if (i > n / i) break;
    if (!(n % i)) return false;
  }
  return true;
}
int Rec(int n, int p) {
  if (n < pr[p]) return 0;
  n /= pr[p];
  int res = n;
  for (int i = (0), _b(p); i < _b; ++i) res -= Rec(n, i);
  return res;
}
int main() {
  int a, b, k;
  cin >> a >> b >> k;
  if (!isPrime(k)) out(0);
  if (k > b / k) out((a <= k && k <= b));
  for (int i = (2), _b(k + 1); i < _b; ++i)
    if (isPrime(i)) pr.push_back(i);
  cout << (Rec(b, ((int)(pr).size()) - 1) - Rec(a - 1, ((int)(pr).size()) - 1))
       << endl;
  return 0;
}
