#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
double fRand(double fMin, double fMax) {
  double f = (double)rand() / RAND_MAX;
  return fMin + f * (fMax - fMin);
}
template <class T>
T min(T a, T b, T c) {
  return min(a, min(b, c));
}
template <class T>
T max(T a, T b, T c) {
  return max(a, max(b, c));
}
bool isPrime(int n) {
  if (n < 2) return false;
  int lim = sqrt(n);
  for (int i = (2); i <= (lim); ++i)
    if (n % i == 0) return false;
  return true;
}
vector<int> prime;
int a, b, k, n;
long long res;
void Try(int i, long long x, int sign) {
  if (i == (int)prime.size() || prime[i] >= k || x * prime[i] > n) {
    res += (n / x) * sign;
    return;
  }
  Try(i + 1, x, sign);
  Try(i + 1, x * prime[i], -sign);
}
int Solve(int x) {
  n = x;
  if (n == 0) return 0;
  if (k > n) return 1;
  res = 0;
  Try(0, 1, 1);
  return res;
}
int main() {
  scanf("%d%d%d", &a, &b, &k);
  if (!isPrime(k)) {
    puts("0");
    return 0;
  }
  for (int i = (2); i <= (sqrt(2000000005)); ++i)
    if (isPrime(i)) prime.push_back(i);
  cout << Solve(b / k) - Solve((a - 1) / k);
  return 0;
}
