#include <bits/stdc++.h>
using namespace std;
long long a, b, k;
bool flag[50000];
int p[50000], tot;
int c[50000], num;
long long solve(long long x) {
  long long X = (a + x - 1) / x * x;
  long long Y = b / x * x;
  return (Y - X) / x + 1;
}
long long dfs(long long x, int from) {
  long long res = 0;
  for (int i = from; i < num; i++) {
    if (x * c[i] > b) break;
    res += solve(x * c[i]);
    res -= dfs(x * c[i], i + 1);
  }
  return res;
}
int main() {
  cin >> a >> b >> k;
  for (int i = 2; i < 50000; i++) {
    if (!flag[i]) p[tot++] = i;
    for (int j = 0; j < tot && i * p[j] < 50000; j++) {
      flag[i * p[j]] = 1;
      if (i % p[j] == 0) break;
    }
  }
  for (int i = 2; i * i <= k; i++)
    if (k % i == 0) {
      printf("0");
      return 0;
    }
  for (int i = 0; i < tot && p[i] * k <= b && p[i] < k; i++) c[num++] = p[i];
  cout << solve(k) - dfs(k, 0);
}
