#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1e17 + 7;
const unsigned long long BASE = 33;
const int N = 1e5 + 7;
const int INF = 1e9 + 7;
const int MOD = 2e9 + 7;
const double Pi = acos(-1.);
const double EPS = 1e-8;
long long kpow(long long a, long long b) {
  long long ret = 1;
  for (; b; b >>= 1, a = a * a)
    if (b & 1) ret = ret * a;
  return ret;
}
const int w[] = {1, -1};
int a, b, k, v[N];
vector<int> pri;
bool isp(int t) {
  for (int i = 2; i < (1 + (int)sqrt(t)); ++i)
    if (t % i == 0) {
      return false;
    }
  return true;
}
void init() {
  for (long long x = 2; x * x <= MOD; ++x)
    if (!v[x]) {
      pri.push_back(x);
      for (long long y = x * x; y < N; y += x) v[y] = true;
    }
}
int solve(int n) {
  int ret = n;
  vector<pair<int, bool> > p;
  p.push_back(make_pair(1, 0));
  for (int i = 0; i < (((int)((pri).size()))); ++i) {
    if (pri[i] >= k) break;
    int m = ((int)((p).size()));
    for (int j = 0; j < (m); ++j) {
      long long x = p[j].first;
      if (x * pri[i] <= n) {
        p.push_back(make_pair(x * pri[i], p[j].second ^ 1));
        ret += w[p[j].second ^ 1] * (n / (x * pri[i]));
      }
    }
  }
  return ret;
}
int main() {
  scanf("%d%d%d", &a, &b, &k);
  if (isp(k)) {
    --a, init();
    printf("%d", solve(b / k) - solve(a / k));
  } else {
    puts("0");
  }
  return 0;
}
