#include <bits/stdc++.h>
using namespace std;
const int maxS = 45000;
bitset<maxS> ip;
void sieve() {
  ip.set();
  ip[0] = ip[1] = 0;
  for (int i = 2; i * i < maxS; i++)
    if (ip[i])
      for (int j = i * i; j < maxS; j += i) ip[j] = 0;
}
bool isPrime(int x) {
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0) return 0;
  return 1;
}
vector<int> primes;
int cnt[(1 << 25)];
int solve1(int mx, int k) {
  cnt[0] = mx / k;
  int n = primes.size();
  vector<pair<int, int> > vec;
  for (int i = 1, pr = 0; pr < 25; i <<= 1, pr++)
    vec.push_back(pair<int, int>(i, pr));
  int ret = mx / k;
  for (int mask = 1; mask < (1 << n); mask++) {
    int bm = (mask & (mask - 1));
    int pr =
        vec[lower_bound(vec.begin(), vec.end(), pair<int, int>(mask ^ bm, -1)) -
            vec.begin()]
            .second;
    cnt[mask] = -(cnt[bm] / primes[pr]);
    ret += cnt[mask];
  }
  return ret;
}
int a, b, k;
int solve2() {
  int ret = 0;
  for (long long i = 1LL * k * ((a + k - 1) / k); i <= b; i += k) {
    int v = i;
    bool ok = 1;
    for (int j = 0; j < primes.size() && ok && primes[j] * primes[j] <= v; j++)
      if (v % primes[j] == 0) ok = 0;
    if (ok) ret++;
  }
  return ret;
}
int main() {
  cin >> a >> b >> k;
  if (!isPrime(k)) return puts("0");
  sieve();
  for (int i = 2; i < k && i <= 44721; i++)
    if (ip[i]) primes.push_back(i);
  if (k <= 100)
    cout << solve1(b, k) - solve1(a - 1, k);
  else
    cout << solve2();
}
