#include <bits/stdc++.h>
using namespace std;
long double TL = 1.0;
bool is_tl = 0;
int CALLS = 0;
inline bool IS() {
  if (++CALLS == 1000) {
    CALLS = 0;
    is_tl |= clock() > (TL - 0.1) * CLOCKS_PER_SEC;
  }
  return is_tl;
}
template <typename T1, typename T2>
inline void amin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void amax(T1 &a, T2 b) {
  if (a < b) a = b;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> &p) {
  os << p.first << ' ' << p.second << '\n';
  return os;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto &u : v) os << u << ' ';
  os << '\n';
  return os;
}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e6 + 7, NS = 2e3 + 7, lg = 19, sq = 550, inf = 2e9 + 7,
          SM = 1e2 + 7;
const long double eps = 1e-9;
int hash_mod[4] = {1000000007, 998244353, 1000000009, 999999937},
    mod = hash_mod[rnd() % 4];
int hash_pows[4] = {179, 239, 1007, 2003}, P = hash_pows[rnd() % 4];
int a, b, k;
bool d[40000000];
bool isprime(int x) {
  for (int j = 2; j * j <= x; j++) {
    if (x % j == 0) return 0;
  }
  return 1;
}
int get1(int n) {
  for (int i = 0; i <= n / k; i++) d[i] = 0;
  for (int i = 2; i * i <= n && i < k; i++) {
    for (int j = 0; j <= n / k; j += i) {
      d[j] = 1;
    }
  }
  int sum = 0;
  if (n >= k) sum++;
  for (int i = 2; i <= n / k; i++) {
    if (d[i] == 0) sum++;
  }
  return sum;
}
int get2(int n) {
  vector<int> v;
  for (int i = 2; i < k; i++) {
    if (isprime(i)) v.push_back(i);
  }
  int m = v.size();
  int res = 0;
  n /= k;
  for (int mask = 0; mask < (1 << m); mask++) {
    int pr = 1, ch = 0;
    for (int i = 0; i < m; i++) {
      if (mask & (1 << i)) {
        if (pr > n / v[i]) pr = 0;
        pr *= v[i];
        ch = 1 - ch;
      }
    }
    if (pr < 2) continue;
    int cnt = n / pr;
    if (ch)
      res += cnt;
    else
      res -= cnt;
  }
  return n - res;
}
int get(int n) {
  if (n / k <= 4e7) {
    return get1(n);
  } else {
    return get2(n);
  }
}
void solve() {
  cin >> a >> b >> k;
  if (!isprime(k)) {
    cout << 0;
    return;
  }
  cout << get(b) - get(a - 1);
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
