#include <bits/stdc++.h>
using namespace std;
const int N = 110000;
const int inf = 1e9;
int a, b, k, p[N], prime[N], cnt, lcnt, rcnt, oldcnt;
pair<int, int> l[N], r[N], old[N];
void checkPrime(int n) {
  for (int i = 2; i <= n; i++) {
    if (p[i] == 0) {
      p[i] = i;
      prime[cnt++] = i;
    }
    for (int j = 0; j < cnt && prime[j] <= p[i] && i * prime[j] <= n; j++)
      p[i * prime[j]] = prime[j];
  }
}
int solve(int a) {
  int ans = 0;
  old[0].first = 1;
  old[0].second = a;
  oldcnt = 1;
  for (int i = 1; i < cnt; i++) {
    lcnt = rcnt = 0;
    for (int j = 0; j < oldcnt; j++) {
      l[lcnt++] = old[j];
      if (old[j].second / prime[i] > 0)
        r[rcnt++] = make_pair(-1 * old[j].first, old[j].second / prime[i]);
    }
    oldcnt = 0;
    int lp = 0, rp = 0;
    pair<int, int> cur;
    while (lp < lcnt && rp < rcnt) {
      if (l[lp].second < r[rp].second) {
        cur = l[lp];
        lp++;
      } else {
        cur = r[rp];
        rp++;
      }
      if (oldcnt && old[oldcnt - 1].second == cur.second)
        old[oldcnt - 1].first += cur.first;
      else
        old[oldcnt++] = cur;
    }
    while (lp < lcnt) {
      cur = l[lp];
      lp++;
      if (oldcnt && old[oldcnt - 1].second == cur.second)
        old[oldcnt - 1].first += cur.first;
      else
        old[oldcnt++] = cur;
    }
    while (rp < rcnt) {
      cur = r[rp];
      rp++;
      if (oldcnt && old[oldcnt - 1].second == cur.second)
        old[oldcnt - 1].first += cur.first;
      else
        old[oldcnt++] = cur;
    }
  }
  for (int i = 0; i < oldcnt; i++) ans += old[i].first * old[i].second;
  return ans;
}
int main() {
  cin >> a >> b >> k;
  int kIsPrime = 1;
  for (int i = 2; i * i <= k; i++)
    if (k % i == 0) {
      kIsPrime = 0;
      break;
    }
  if (!kIsPrime) {
    cout << 0;
    return 0;
  }
  if ((unsigned long long)k * k > b) {
    if (k >= a && k <= b)
      cout << 1;
    else
      cout << 0;
    return 0;
  }
  checkPrime(k);
  if (p[k] != k) {
    cout << 0;
    return 0;
  }
  reverse(prime, prime + cnt);
  int ans = solve(b / k) - solve((a - 1) / k);
  cout << ans;
}
