#include <bits/stdc++.h>
int getPrime(int n, int p[]) {
  int i, j, n2 = n / 2;
  for (i = 0; i < n2; i++) p[i] = 1;
  for (i = 3; i * i < n; i += 2)
    if (p[i >> 1])
      for (j = (i * i) >> 1; j < n2; j += i) p[j] = 0;
  j = 1;
  p[0] = 2;
  for (i = 1; i < n2; i++)
    if (p[i]) p[j++] = i * 2 + 1;
  return j;
}
int ps, p[44791];
long long res, pp;
int a, b, n;
void solve(long long now, int st, int num) {
  int i, j, k;
  long long send, add;
  add = b / now - (a - 1) / now;
  if (num % 2) add *= -1;
  res += add;
  for (i = st; i < pp; i++) {
    send = now * p[i];
    if (send > b) break;
    solve(send, i + 1, num + 1);
  }
}
int is_prime(int n) {
  int i;
  for (i = 0; i < ps; i++) {
    if (p[i] * p[i] > n) break;
    if (n % p[i] == 0) return 0;
  }
  return 1;
}
int main() {
  int i, j, k, l, m;
  ps = getPrime(44791, p);
  while (scanf("%d%d%d", &a, &b, &n) == 3) {
    for (i = 0; i < ps; i++)
      if (n == p[i]) break;
    if (i == ps) {
      if (a <= n && n <= b && is_prime(n))
        puts("1");
      else
        puts("0");
      continue;
    }
    pp = i;
    res = 0;
    solve(n, 0, 0);
    printf("%d\n", (int)res);
  }
  return 0;
}
