#include void chmin(long long* a, long long b) { if (*a > b) *a = b; } long long count(long long N, long long M) { int i, j, k, m[100] = {}; long long p[100]; for (i = 2, k = 0; M / i >= i; i++) { if (M % i == 0) { p[k] = i; while (M % i == 0) { M /= i; m[k]++; } k++; } } if (M > 1) { p[k] = M; m[k++] = 1; } long long ans = 1LL << 60, tmp, X; for (i = 0; i < k; i++) { for (X = p[i], tmp = 0; 1; X *= p[i]) { tmp += N / X; if (X > N / p[i]) break; } chmin(&ans, tmp); } return ans; } int main() { long long N, K, M; scanf("%lld %lld %lld", &N, &K, &M); printf("%lld\n", count(N, M) - count(N - K, M) - count(K, M)); fflush(stdout); return 0; }