using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static long[] NList => ReadLine().Split().Select(long.Parse).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, k, m) = (c[0], c[1], c[2]); WriteLine(Divs(n, m) - Divs(n - k - 1, m) - Divs(k, m)); } static long Divs(long n, long p) { var prev = 1L; var ans = 0L; while (true) { var pc = prev * p; if (pc / p != prev) break; ans += n / pc; prev = pc; } return ans; } }