#include <bits/stdc++.h>
using namespace std;
bool GetPrime(long long k) {
  for (long long i = 2; i <= sqrt(k); i++)
    if (k % i == 0) return 0;
  return 1;
}
long long GetAns(long long x, long long k) {
  if (GetPrime(k) == 0) return 0;
  long long sum = x / k;
  for (long long i = 2; i <= min(x / k, k - 1); i++) sum -= GetAns(x / k, i);
  return sum;
}
signed main() {
  long long l, r, k;
  cin >> l >> r >> k;
  cout << GetAns(r, k) - GetAns(l - 1, k);
  return 0;
}
