var d,i,j:longint;
m:array[1..1000000]of int64;
v:array[1..1000000]of boolean;
ans,a,b:int64;
begin
assign(input,'parents.in');reset(input);
assign(output,'parents.out');rewrite(output);
readln(a,b,d);close(input);
a:=a div d;b:=b div d;
if a>b then
begin a:=a xor b;b:=a xor b;a:=a xor b;end;
fillqword(m,sizeof(m)>>3,1);
for i:=2 to b do
begin
if v[i]then continue;
m[i]:=-1;
j:=i+i;
while j<=b do
begin
v[j]:=true;
if j div i mod i=0 then m[j]:=0
else m[j]:=-m[j];
j:=j+i;
end;
end;
for i:=1 to a do
ans:=ans+m[i]*(a div i)*(b div i);
writeln(ans);close(output);
end.