#include <bits/stdc++.h>
using namespace std;
const double pi = 3.1415926535;
const double eps = 1e-6;
bool bl[110000];
int ans, k;
void dfs(int a, int l, int flag) {
  if (a == 0) return;
  ans += flag * a;
  for (int i = l + 1; i <= min(k - 1, a); i++)
    if (!bl[i]) dfs(a / i, i, -flag);
}
int work(int a) {
  int l = a / k;
  if (l <= 1) return l;
  if (l < k) return 1;
  ans = 0;
  dfs(l, 1, 1);
  return ans;
}
bool isprim(int a) {
  for (int i = 2; i * i <= a; i++)
    if (a % i == 0) return 0;
  return 1;
}
int main() {
  for (int i = 2; i <= 100000; i++)
    if (!bl[i])
      for (int j = 2; i * j <= 100000; j++) bl[i * j] = 1;
  int a, b;
  scanf("%d%d%d", &a, &b, &k);
  if (!isprim(k)) {
    cout << 0 << endl;
    return 0;
  }
  cout << work(b) - work(a - 1) << endl;
  cin >> a;
}
