Pagini recente » Cod sursa (job #2298252) | Cod sursa (job #1938146) | Cod sursa (job #1315050) | Cod sursa (job #2317659) | Cod sursa (job #494492)
Cod sursa(job #494492)
var nr,i:word;
r,max1,combinare:longint;
d:byte;
f,g:text;
function max(a,b:longint):longint;
begin
if a-b>b then
max:=a-b
else
max:=b;
end;
function comb(c:longint):longint;
var j,p:longint;
begin
p:=1;
for j:=c+1 to r do
p:=p*j;
for j:=1 to r-c do
p:=p div j;
comb:=p;
end;
begin
assign(f,'pascal.in');
reset(f);
assign(g,'pascal.out');
rewrite(g);
readln(f,r,d);
nr:=0;
for i:=1 to r div 2 do
begin
max1:=max(r,i);
combinare:=comb(max1);
if (r mod 2=0) and (i<>r div 2) and (combinare mod d=0) then
nr:=nr+2
else
if (r mod 2=0) and (i=r div 2) and (combinare mod d=0) then
nr:=nr+1
else
if (r mod 2<>0) and (combinare mod d=0) then
nr:=nr+2;
end;
write(g,nr);
close(f);
close(g);
end.