#include <iostream>
using namespace std;
long long A,B,i,j,d,k1,k2,f[1000002];
int main()
{
freopen("parents.in","r",stdin);
freopen("parents.out","w",stdout);
scanf("%d%d%d",&A,&B,&d);
k1=A/d;
k2=B/d;
if (k1>k2) swap(k1,k2);
f[k1]=k2/k1;
for (i=k1-1;i>=1;i--)
{
f[i]=(k2/i)*(k1/i);
if (k2/(i+1)==k2/i && k1/(i+1)==k1/i)
{
f[i]=f[i+1];
continue;
}
for (j=i*2;j<=k1;j+=i)
f[i]-=f[j];
}
cout<<f[1]<<endl;
return 0;
}