Pagini recente » Cod sursa (job #421959) | Cod sursa (job #727384) | Cod sursa (job #389183) | Cod sursa (job #831190) | Cod sursa (job #58434)
Cod sursa(job #58434)
var k,suma,n,d,rez,ct:int64;
i,c:longint;
fi,fo:text;
function putere(n,p:int64):int64;
begin
k:=1;
while k<=n do
begin
k:=k*p;
suma:=suma+(n div k);
end;
putere:=suma;
suma:=0;
end;
begin
assign(fi,'pascal.in'); reset(fi);
assign(fo,'pascal.out'); rewrite(fo);
read(fi,n,d);
ct:=0;
if n mod 2=0 then
begin
for i:=1 to (n-1)div 2 + 1 do
begin
if d=4 then c:=2
else c:=d;
rez:=putere(n,c)-putere(n-i,c)-putere(i,c);
if d=4 then
if rez>=2 then inc(ct)
else
else
if rez>=1 then inc(ct);
end;
if ct <> 0 then ct:=ct*2-1;
end
else
begin
for i:=1 to (n-1)div 2 do
begin
rez:=putere(n,d)-putere(n-i,d)-putere(i,d);
if d=4 then
if rez>=2 then inc(ct)
else
else
if rez>=1 then inc(ct);
end;
if ct<>0 then ct:=ct*2
end;
writeln(fo,ct);
close(fi);
close(fo);
end.