#include <bits/stdc++.h>
using namespace std;
void desperate_optimization(int precision) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.setf(ios::showpoint);
  cout.precision(precision);
}
bool notPrime(long long k) {
  for (long long i = 2; i * i <= k; i++)
    if (k % i == 0) return true;
  return false;
}
const int N = 45000;
int primes[N + 5];
vector<long long> prime;
void sieve(int k) {
  int bound = min(k, N);
  for (int i = 2; i < bound; i++) {
    if (primes[i] == 0) {
      prime.push_back(i);
      for (int j = i; j < bound; j += i) primes[j] = i;
    }
  }
}
long long a, b;
long long k;
long long red = 0;
void solve(int idx, long long mul, int op) {
  if (idx == prime.size()) return;
  long long nm = mul * prime[idx];
  if (nm * k > b) return;
  if (nm <= b) {
    red += (b / (k * nm) - (a - 1) / (k * nm)) * op;
    solve(idx + 1, nm, -op);
  }
  solve(idx + 1, mul, op);
}
void hora(int tc) {
  cin >> a >> b >> k;
  if (notPrime(k)) {
    cout << 0 << endl;
    return;
  }
  sieve(k);
  solve(0, 1, 1);
  long long res = b / k - (a - 1) / k - red;
  cout << res << endl;
}
int main() {
  desperate_optimization(10);
  int ntc = 1;
  for (int tc = 1; tc <= ntc; tc++) hora(tc);
  return 0;
}
