#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:167767260")
const int INF = 1000000000;
using namespace std;
int a, b, k, i, uns[20000000], U, j, N;
vector<int> g;
long long V;
void run(int no, int num, long long ss);
int f(int n) {
  N = n;
  V = 0;
  run(0, 0, 1);
  return V;
}
void run(int no, int num, long long ss) {
  if (no == (int)g.size()) {
    if (num % 2 == 1) {
      V -= N / ss;
    } else {
      V += N / ss;
    }
  } else {
    if (ss * g[no] <= N) run(no + 1, num + 1, ss * g[no]);
    run(no + 1, num, ss);
  }
}
int main() {
  cin >> a >> b >> k;
  a = ((a - 1) / k + 1) * k;
  b = (b / k) * k;
  if (a > b) {
    cout << "0" << endl;
    return 0;
  }
  for (i = 2; i * i <= k; i++)
    if (k % i == 0) {
      cout << "0" << endl;
      return 0;
    }
  if (k >= 1000) {
    for (i = 1; i <= 2000000; i++) uns[i] = i;
    for (i = 2; i * i <= 2000000; i++) {
      if (uns[i] == i) {
        for (j = i; j <= 2000000; j += i) uns[j] = min(uns[j], i);
      }
    }
    U = 0;
    for (i = a / k; i <= b / k; i++)
      if (uns[i] == 1 || uns[i] >= k) U++;
    cout << U << endl;
    return 0;
  }
  g.clear();
  for (i = 2; i <= k - 1; i++) {
    bool is = true;
    for (j = 2; j <= i - 1; j++)
      if (i % j == 0) is = false;
    if (is) g.push_back(i);
  }
  U = f(b / k) - f(a / k - 1);
  cout << U << endl;
}
