#include <bits/stdc++.h>
using namespace std;
const int maxn = 150010;
long long Sqr, vis[maxn], pri[maxn], sp[maxn], tot, m, id1[maxn], id2[maxn];
long long g[maxn], h[maxn], w[maxn];
void Sieve(int n) {
  tot = 0;
  vis[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (!vis[i]) pri[++tot] = i, sp[tot] = sp[tot - 1] + i;
    for (int j = 1; i * pri[j] <= n; j++) {
      vis[i * pri[j]] = 1;
      if (i % pri[j] == 0) break;
    }
  }
}
bool check(int P) {
  for (int i = 2; i * i <= P; i++)
    if (P % i == 0) return false;
  return true;
}
long long solve(long long n, long long K) {
  if (n < K) return 0;
  if (!check(K)) return 0;
  if (K > n / K) return 1;
  Sqr = sqrt(n);
  Sieve(Sqr);
  long long res = 0;
  m = 0;
  for (long long i = 1, j; i <= n; i = j + 1) {
    j = n / (n / i);
    w[++m] = n / i;
    if (w[m] <= Sqr)
      id1[w[m]] = m;
    else
      id2[n / w[m]] = m;
    g[m] = w[m] - 1;
  }
  for (int j = 1; j <= tot; j++) {
    for (int i = 1; i <= m && pri[j] * pri[j] <= w[i]; i++) {
      int k = (w[i] / pri[j] <= Sqr) ? id1[w[i] / pri[j]]
                                     : id2[n / (w[i] / pri[j])];
      g[i] = g[i] - (g[k] - (j - 1));
      if (pri[j] == K && i == 1) res += g[k] - (j - 1);
    }
  }
  return res + 1;
}
int main() {
  long long l, r, k;
  scanf("%lld%lld%lld", &l, &r, &k);
  printf("%lld\n", solve(r, k) - solve(l - 1, k));
  return 0;
}
