#include <bits/stdc++.h>
int A, B, m, li[100005], tot, res;
bool pri[100005];
void dfs(int o, int s, int u) {
  if (o > li[0] || (long long)s * li[o] > tot) return;
  dfs(o + 1, s, u);
  s *= li[o];
  res += tot / s * u;
  dfs(o + 1, s, -u);
}
inline int calc(int x) {
  if (!x) return 0;
  if (x < m) return 0;
  if (x < (long long)m * m) return 1;
  tot = x / m;
  res = tot;
  li[0] = 0;
  for (int i = 2; i < m; ++i)
    if (pri[i]) li[++li[0]] = i;
  dfs(1, 1, -1);
  return res;
}
int main() {
  memset(pri, 1, sizeof(pri));
  pri[1] = 0;
  for (int i = 2; i <= 100000; ++i)
    if (pri[i] && i <= 100000 / i)
      for (int j = i * i; j <= 100000; j += i) pri[j] = 0;
  scanf("%d%d%d", &A, &B, &m);
  bool ff = 1;
  for (int i = 2; i <= m / i; ++i)
    if (!(m % i)) {
      ff = 0;
      break;
    }
  if (!ff)
    puts("0");
  else {
    printf("%d\n", calc(B) - calc(A - 1));
  }
  return 0;
}
