program C0487;
var S:array[1..9592] of longint;
f,cup:array[1..100000] of longint;
a,b,p,i,j,t,x,y,ans:longint;
function father(x:longint):longint;
begin
if f[x]=x then exit(x);
f[x]:=father(f[x]);
father:=f[x];
end;
function check(s:longint):boolean;
var i:longint;
begin
if s=1 then exit(false);
if s=2 then exit(true);
for i:=2 to trunc(sqrt(s)) do
if s mod i=0 then exit(false);
check:=true;
end;
function checkPr(u,v:longint):boolean;
var i:longint;
begin
for i:=1 to t do
if (u mod S[i]=0) and (v mod S[i]=0) then exit(true);
checkPr:=false;
end;
begin
assign(input,'setb.in');
reset(input);
assign(output,'setb.out');
rewrite(output);
readln(a,b,p);
t:=0;
for i:=p to b do
if check(i) then begin
inc(t);
S[t]:=i;
end;
for i:=a to b do f[i]:=i;
for i:=a to b-1 do
for j:=i+1 to b do begin
x:=father(i);
y:=father(j);
if x<>y then
if checkPr(i,j) then f[x]:=y;
end;
for i:=a to b do f[i]:=father(f[i]);
fillchar(cup,sizeof(cup),0);
for i:=a to b do inc(cup[f[i]]);
ans:=0;
for i:=a to b do
if cup[i]<>0 then inc(ans);
writeln(ans);
close(input);
close(output);
end.