#include <bits/stdc++.h>
bool visited[45000] = {0};
int prime[5005], cnt = 0;
const int max_p = 44987;
int calc(int n, int k) {
  int ret = 0;
  if (k > n) return 0;
  if (k * k > n) return 1;
  ret = n / k;
  for (int i = 0; prime[i] * prime[i] < n && prime[i] < k; i++)
    ret -= calc(n / k, prime[i]);
  return ret;
}
int main() {
  int a, b, k, ans;
  scanf("%d%d%d", &a, &b, &k);
  for (int i = 2; i <= 45000; i++) {
    if (!visited[i]) {
      prime[cnt++] = i;
      for (int j = i * i; j <= 45000; j += i) {
        visited[j] = true;
      }
    }
  }
  for (int i = 2; i * i <= k; i++)
    if (k % i == 0) {
      printf("0\n");
      return 0;
    }
  ans = calc(b, k) - calc(a - 1, k);
  printf("%d\n", ans);
}
