#include <bits/stdc++.h>
using namespace std;
int minFact[1000000 + 5];
vector<int> prime;
int rec(int N, int K) {
  int ans = 0;
  if (N / K <= 10000) {
    ans = 0;
    for (int i = 1; i <= N / K; ++i) {
      ans += (minFact[i] >= K);
    }
  } else {
    ans = N / K;
    for (int i = 0; i < prime.size() and prime[i] < K; ++i) {
      ans -= rec(N / K, prime[i]);
    }
  }
  return ans;
}
int main() {
  minFact[1] = 2 * 1000000007;
  for (int i = 2; i <= 100000; ++i) {
    if (minFact[i] == 0) {
      prime.push_back(i);
      for (int j = i; j <= 100000; j += i) {
        if (minFact[j] == 0) minFact[j] = i;
      }
    }
  }
  int L, R, K;
  cin >> L >> R >> K;
  for (int i = 2; i * i <= K; ++i) {
    if (K % i == 0) {
      cout << 0;
      return 0;
    }
  }
  cout << rec(R, K) - rec(L - 1, K);
}
