#include <bits/stdc++.h>
using namespace std;
using cd = complex<double>;
const int Inf = 1000000007;
const long long mod = 1000000007;
const double Pi = acos(-1);
void Fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
int l, r, k;
bool Prime(int x) {
  if (x == 2 or x == 3) {
    return true;
  }
  if (x % 2 == 0 or x % 3 == 0) {
    return false;
  }
  for (int i = 5; i <= sqrt(x); i = i + 6) {
    if (x % i == 0 or x % (i + 2) == 0) {
      return false;
    }
  }
  return true;
}
int Solve(int x, int p) {
  if (x == 0 or !Prime(p)) {
    return 0;
  }
  x /= p;
  int ans = x;
  for (int i = 2; i <= min(p - 1, x); i++) {
    ans -= Solve(x, i);
  }
  return ans;
}
int main() {
  Fastio();
  cin >> l >> r >> k;
  cout << Solve(r, k) - Solve(l - 1, k);
}
