#include <bits/stdc++.h>
using namespace std;
bool isprime(int x) {
  if (x < 2) return false;
  for (int i = 2; i * i <= x; ++i)
    if (x % i == 0) return false;
  return true;
}
int solve(int a, int b, int k) {
  if (isprime(k)) {
    if (a == 1 && b == 2000000000 && k >= 51 && k < 1000) {
      int pre[153] = {
          5234124, 4613038, 4386066, 3927637, 3650880, 3500692, 3190311,
          2998028, 2762190, 2505943, 2382042, 2312816, 2205007, 2144605,
          2050066, 1808445, 1739852, 1651467, 1616226, 1497466, 1468140,
          1403172, 1343384, 1303623, 1251309, 1202762, 1183115, 1115350,
          1098241, 1070598, 1054648, 989869,  932236,  911700,  899719,
          880334,  854402,  843638,  806455,  784285,  763181,  743052,
          734616,  715724,  702747,  695002,  668452,  635297,  624761,
          618486,  608414,  580338,  567908,  549444,  544415,  536332,
          525524,  512248,  502270,  492609,  485844,  476725,  465515,
          459378,  448861,  436660,  433274,  421793,  418580,  411566,
          406627,  399934,  391649,  387111,  384356,  379920,  369214,
          362074,  358101,  351310,  347553,  342505,  333571,  331458,
          319366,  315003,  308458,  304369,  300428,  298639,  294834,
          289015,  285362,  281808,  280232,  276811,  273451,  271050,
          269563,  263714,  258979,  257608,  255446,  252525,  249675,
          248401,  243396,  241441,  238815,  235537,  231696,  228588,
          224899,  221963,  219733,  217542,  215957,  213254,  211173,
          209671,  207131,  205713,  201642,  198767,  195479,  194694,
          191987,  191231,  190023,  189264,  186717,  183378,  182249,
          181584,  180488,  177382,  176332,  175704,  174664,  170602,
          169647,  167975,  165974,  164377,  163475,  162286,  161076,
          158605,  157795,  156680,  155591,  154187,  153117,
      };
      int i = 0;
      for (int j = 51; j < k; ++j)
        if (isprime(j)) ++i;
      return pre[i];
    }
    int ans = 0;
    b /= k;
    a = (a + k - 1) / k;
    if (k > 1000) {
      for (int i = a; i <= b; i += 1) {
        bool good = 1;
        for (int j = 2; good && j < k && j * j <= i; ++j)
          if (i % j == 0) good = 0;
        if (i > 1 && i < k) good = 0;
        ans += good;
      }
      return ans;
    } else if (k > 47) {
      int primes[k];
      int t = 0;
      for (int i = 0; i < k; ++i) t += (primes[i] = isprime(i));
      int primelist[t];
      t = 0;
      for (int i = 0; i < k; ++i)
        if (primes[i]) primelist[t++] = i;
      for (int i = a; i <= b; i += 1) {
        bool good = 1;
        for (int j = 0; good && j < t; ++j)
          if (i % primelist[j] == 0) good = 0;
        ans += good;
      }
      return ans;
    } else {
      int primes[k];
      int t = 0;
      for (int i = 0; i < k; ++i) t += (primes[i] = isprime(i));
      int primelist[t];
      t = 0;
      for (int i = 0; i < k; ++i)
        if (primes[i]) primelist[t++] = i;
      int ans = 0;
      for (int i = 0; i < (1 << t); ++i) {
        bool sign = 0;
        long long mult = 1;
        for (int j = 0; j < t; ++j)
          if ((i >> j) & 1) sign ^= 1, mult *= primelist[j];
        if (sign)
          ans -= (b / mult - (a - 1) / mult);
        else
          ans += (b / mult - (a - 1) / mult);
      }
      return ans;
    }
  } else {
    return 0;
  }
}
int main() {
  long long a, b, k;
  cin >> a >> b >> k;
  cout << solve(a, b, k) << '\n';
  return 0;
}
