#include <bits/stdc++.h>
using namespace std;
int a, b, k, say, dp[2][100000];
vector<int> v;
map<pair<int, int>, int> mp;
int asal(int x) {
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0) return 0;
  return 1;
}
int hes(int s, int x) {
  if (s == 0) return 0;
  if (mp[make_pair(s, x)]) return mp[make_pair(s, x)];
  say++;
  int cev = s / v[x];
  if (cev == 0) return 0;
  for (int i = 0; i < x; i++) cev -= hes(s / v[x], i);
  return mp[make_pair(s, x)] = cev;
}
int main() {
  scanf("%d %d %d", &a, &b, &k);
  if (k * 1ll * k >= b && a <= k && k <= b && asal(k)) {
    printf("1\n");
    return 0;
  }
  if (k * 1ll * k >= b || !asal(k)) {
    printf("0\n");
    return 0;
  }
  for (int i = 2; i <= k; i++)
    if (asal(i)) v.push_back(i);
  printf("%d\n", hes(b, v.size() - 1) - hes(a - 1, v.size() - 1));
}
