#include <bits/stdc++.h>
using namespace std;
const long long N = 45000, inf = 2e9;
long long a[N];
map<long long, long long> mp[N];
vector<long long> P;
long long l, r, res;
void dfs(long long idx, long long val, long long sign) {
  if (val > r) return;
  res += sign * (r / val - (l - 1) / val);
  for (long long i = 0; i < idx; i++) dfs(i, val * P[i], -sign);
}
long long Prime(long long x) {
  for (long long i = 2; i * i <= x; i++)
    if (x % i == 0) return 0;
  return 1;
}
int32_t main() {
  long long k;
  cin >> l >> r >> k;
  for (long long i = 2; i < N; i++)
    if (!a[i]) {
      for (long long j = i; j < N; j += i) {
        a[j] = 1;
      }
      if (i < k) {
        P.push_back(i);
      }
    }
  if (!Prime(k))
    cout << 0 << endl;
  else if (k >= N)
    cout << (k >= l && k <= r) << endl;
  else {
    dfs(P.size(), k, 1);
    cout << res << endl;
  }
}
