#include <bits/stdc++.h>
using namespace std;
const double PI = 3.1415926535897932384626433832795;
const double EPS = 1e-9;
const int MAX_NUMBER = 2 * 1000 * 1000 * 1000;
const int ROOT = 44721;
const int BORDER = 100;
int minPrimeDivisor[MAX_NUMBER / BORDER];
int smallPrimes[BORDER];
int amountSmallPrimes;
bool isPrime(int n) {
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return n > 1;
}
void precalc() {
  memset(minPrimeDivisor, -1, sizeof(minPrimeDivisor));
  double t = clock();
  for (int i = 2; i < MAX_NUMBER / BORDER; ++i) {
    if (minPrimeDivisor[i] == -1) {
      minPrimeDivisor[i] = i;
      for (int j = i + i; j < MAX_NUMBER / BORDER; j += i) {
        if (minPrimeDivisor[j] == -1) {
          minPrimeDivisor[j] = i;
        }
      }
    }
  }
  t = clock() - t;
  t /= CLOCKS_PER_SEC;
  cerr << "first time is " << t << endl;
  t = clock();
  amountSmallPrimes = 0;
  for (int i = 2; i <= BORDER; ++i) {
    if (isPrime(i)) {
      smallPrimes[amountSmallPrimes++] = i;
    }
  }
}
bool canMult(int a, int b) {
  if (b == 0) {
    return true;
  }
  return a <= MAX_NUMBER / b;
}
void go(int pos, int maskProd, int amountBits, int prime, int border, int& res,
        bool added) {
  if (!added) {
    int sign = (amountBits & 1) ? -1 : +1;
    res += sign * (border / maskProd);
  }
  if (pos == amountSmallPrimes || smallPrimes[pos] == prime) {
    return;
  }
  go(pos + 1, maskProd, amountBits, prime, border, res, true);
  if (canMult(maskProd, smallPrimes[pos])) {
    go(pos + 1, maskProd * smallPrimes[pos], amountBits + 1, prime, border, res,
       false);
  }
}
int getSum(int border, int p) {
  border /= p;
  if (p <= BORDER) {
    int res = 0;
    go(0, 1, 0, p, border, res, false);
    return res;
  } else {
    int res = 0;
    for (int i = 1; i <= border; ++i) {
      if (minPrimeDivisor[i] >= p || minPrimeDivisor[i] == -1) {
        ++res;
      }
    }
    return res;
  }
}
int solve(int a, int b, int k) {
  if (!isPrime(k)) {
    return 0;
  }
  int first = getSum(b, k);
  int second = getSum(a - 1, k);
  int res = first - second;
  return res;
}
int getRand() {
  int x = 0;
  for (int i = 0; i < 3; ++i) {
    x <<= 10;
    x += rand();
  }
  x %= MAX_NUMBER;
  if (x < 0) {
    x = -x;
  }
  x++;
  assert(0 < x && x <= MAX_NUMBER);
  return x;
}
int stuSolve(int a, int b, int k) {
  int res = 0;
  for (int i = a; i <= b; ++i) {
    if (i % k) {
      continue;
    }
    bool ok = true;
    for (int j = 2; j < k; ++j) {
      if (i % j == 0) {
        ok = false;
        break;
      }
    }
    if (ok) {
      ++res;
    }
  }
  return res;
}
void ss() {
  for (int test = 0;; ++test) {
    cerr << "test " << test << " ";
    int a = getRand();
    int b = getRand();
    if (b < a) {
      swap(a, b);
    }
    int k = getRand();
    while (k == 1) {
      k = getRand();
    }
    if (rand() & 1) {
      k = k % 100 + 2;
    }
    int stu = stuSolve(a, b, k);
    int my = solve(a, b, k);
    if (stu != my) {
      cerr << "WA\n";
      cerr << a << " " << b << " " << k << endl;
      cerr << "stu " << stu << endl;
      cerr << "my " << my << endl;
      return;
    } else {
      cerr << "OK\n";
    }
  }
}
int main() {
  precalc();
  int a, b, k;
  while (cin >> a >> b >> k) {
    int res = solve(a, b, k);
    cout << res << endl;
  }
  return 0;
}
