#include <bits/stdc++.h>
using namespace std;
int m;
bool isprime(int x) {
  for (long long i = 2; i * i <= x; i++) {
    if (x % i == 0) return false;
  }
  return true;
}
int primes[100100];
int cnt;
bool can[100100];
int sum;
int res[100100];
void dfs(int cur, int n, long long need) {
  if (cur == cnt) return;
  int base = cur == 0 ? 0 : (res[cur - 1] + 1);
  int sign = (cur & 1) ? -1 : 1;
  for (int i = base; i < cnt; i++) {
    res[cur] = i;
    int ret = n / (need * primes[i]);
    sum += sign * ret;
    if (ret != 0) {
      dfs(cur + 1, n, need * primes[i]);
    }
  }
}
int solve(int x) {
  if (x < m) return 0;
  if ((long long)m * m > x) return 1;
  sum = 0;
  dfs(0, x / m, 1);
  return x / m - sum;
}
int main() {
  int a, b;
  scanf("%d%d%d", &a, &b, &m);
  if (!isprime(m)) {
    printf("0\n");
  } else {
    if ((long long)m * m <= b) {
      memset(can, true, sizeof(can));
      can[0] = can[1] = false;
      cnt = 0;
      for (int i = 2; i < m; i++) {
        if (can[i]) {
          primes[cnt++] = i;
          for (long long j = (long long)i * i; j < m; j += i) {
            can[j] = false;
          }
        }
      }
    }
    printf("%d\n", solve(b) - solve(a - 1));
  }
  return 0;
}
