#include <bits/stdc++.h>
using namespace std;
map<int, bool> primeCache;
inline bool isPrime(int n) {
  if (primeCache.count(n) != 0) {
    return primeCache[n];
  }
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      primeCache[n] = false;
      return false;
    }
  }
  primeCache[n] = true;
  return true;
}
int f(int n, int k) {
  if (n <= 1 or n < k) {
    return 0;
  }
  if (!isPrime(k)) {
    return 0;
  }
  int ret = n / k;
  n /= k;
  for (int i = 2; i < k and i <= n; i++) {
    ret -= f(n, i);
  }
  return ret;
}
int main() {
  int a, b, k;
  cin >> a >> b >> k;
  int ans = f(b, k) - f(a - 1, k);
  cout << ans << endl;
  return 0;
}
