#include <bits/stdc++.h>
using namespace std;
int id = 0, a, b;
int prime[45005];
bool flag[45005];
void sieve() {
  int n = 45000;
  for (int i = 4; i <= n; i += 2) flag[i] = true;
  int sq = sqrt(n);
  for (int i = 3; i * i <= n; i += 2) {
    if (!flag[i])
      for (int j = i + i; j <= n; j += i) flag[j] = true;
  }
  prime[id++] = 2;
  for (int i = 3; i < n; i += 2)
    if (!flag[i]) prime[id++] = i;
}
int solve(int indx, int val, int sign) {
  if (indx == id) {
    return sign * ((b / val) - (a - 1) / val);
  }
  int res = solve(indx + 1, val, sign);
  if ((b / val) >= prime[indx])
    res += solve(indx + 1, val * prime[indx], sign * -1);
  return res;
}
bool isprime(int x) {
  int sq = sqrt(x);
  for (int i = 0; prime[i] <= sq; i++)
    if (x % prime[i] == 0) return false;
  return true;
}
int main() {
  sieve();
  int k;
  cin >> a >> b >> k;
  int sq = sqrt(b);
  if (b < k) {
    cout << 0 << endl;
    return 0;
  }
  if (sq < k) {
    if (a <= k && isprime(k))
      cout << 1 << endl;
    else
      cout << 0 << endl;
    return 0;
  }
  if (flag[k]) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < id; i++) {
    if (prime[i] >= k) {
      id = i;
      break;
    }
  }
  a = (a + k - 1) / k, b = b / k;
  int res = solve(0, 1, 1);
  if (res < 0) res = -res;
  cout << res << endl;
  return 0;
}
