#include <bits/stdc++.h>
using namespace std;
int minp[10000000 + 10];
bool prime[10000000 + 10];
bool isprime(long long p) {
  if (p < 2) return false;
  long long d;
  for (d = 2; d * d <= p; d++)
    if (p % d == 0) return false;
  return true;
}
long long ANS;
vector<long long> v;
void dfs(int pos, int sign, long long x, long long low, long long high) {
  if (pos == v.size()) {
    long long tmp = high / x - (low + x - 1) / x + 1;
    ANS += tmp * sign;
    return;
  }
  dfs(pos + 1, sign, x, low, high);
  if (x * v[pos] <= high) dfs(pos + 1, -sign, x * v[pos], low, high);
}
long long func(long long a, long long b, long long p) {
  int i;
  if (!isprime(p)) return 0;
  a = (a + p - 1) / p;
  b = b / p;
  if (a > b) return 0;
  if (b <= 10000000) {
    long long ans = 0;
    for (i = a; i <= b; i++)
      if (i == 1 || minp[i] >= p) ans++;
    return ans;
  }
  for ((i) = 0; (i) < (int)(p); (i)++)
    if (prime[i]) v.push_back(i);
  dfs(0, 1, 1, a, b);
  return ANS;
}
int main(void) {
  int i, j;
  for (i = 1; i <= 10000000; i++) minp[i] = i;
  for (i = 2; i <= 10000000; i++)
    if (minp[i] == i)
      for (j = 2 * i; j <= 10000000; j += i) minp[j] = min(minp[j], i);
  for (i = 2; i <= 10000000; i++) prime[i] = (minp[i] == i);
  long long a, b, p;
  cin >> a >> b >> p;
  long long ans = func(a, b, p);
  cout << ans << endl;
  return 0;
}
