Cod sursa(job #121456)

Utilizator claudiu_syclaudiu claudiu_sy Data 8 ianuarie 2008 20:26:05
Problema Pascal Scor 20
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.72 kb
var j,r,d,p:longint;
    a,b,c,n:longint;
    f,g:text;
    ok,oki:boolean;

function fact(e:longint):longint;
begin
if e=0 then fact:=1
       else fact:=e*fact(e-1);
end;


begin
assign(f,'pascal.in');
assign(g,'pascal.out');
reset(f);
rewrite(g);
readln(f,r,d);
c:=fact(r);
ok:=true;
if r mod 2=0 then ok:=false;
for j:=0 to ((r-1) div 2) do
    begin
    oki:=false;
    a:=fact(j);
    b:=fact(r-j);
    n:=c div (a*b);
    if n mod d=0 then
       p:=p+1;
    end;


if ok then
   p:=p*2
   else begin
        p:=p*2;
        a:=fact(j+1);
        b:=fact(r-j-1);
        n:=c div (a*b);
        if n mod d=0 then
           p:=p+1;
        end;

writeln(g,p);
close(f);
close(g);
end.