#include <bits/stdc++.h>
using namespace std;
const long long ts = 100005;
int bound, n, a, b, k, boundleft, boundright, ans;
vector<int> pr, f(ts * 5, 0), T(ts * 5);
void build_seive(int bound) {
  for (int i = 2; i <= bound; i++) {
    if (f[i] == 0) {
      f[i] = i;
      pr.push_back(i);
    }
    for (int j = 0; j < (int)pr.size() && pr[j] <= f[i] && pr[j] * i <= bound;
         j++) {
      f[i * pr[j]] = pr[j];
    }
  }
}
bool prime(int p) {
  for (int i = 2; i <= sqrt(p); i++) {
    if (p % i == 0) return 0;
  }
  return 1;
}
int calc(int num, int p) {
  if (num == 0 || !prime(p)) return 0;
  int ans = num;
  for (int j = 0; j < (int)pr.size() && pr[j] < p && pr[j] <= num; j++) {
    ans -= calc(num / pr[j], pr[j]);
  }
  return ans;
}
int main() {
  cin >> a >> b >> k;
  build_seive(min(b / k, k));
  cout << calc(b / k, k) - calc((a - 1) / k, k);
}
