Pagini recente » Cod sursa (job #1262271) | Cod sursa (job #3144068) | Cod sursa (job #666940) | Cod sursa (job #2289503) | Cod sursa (job #58331)
Cod sursa(job #58331)
var k,suma,n,d,rez,ct:int64;
i: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
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;
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;
ct:=ct*2
end;
writeln(fo,ct);
close(fi);
close(fo);
end.