Pagini recente » Cod sursa (job #116386) | Cod sursa (job #1580887) | Cod sursa (job #1606240) | Cod sursa (job #1860706) | Cod sursa (job #40573)
Cod sursa(job #40573)
var p,s,s1,s2,x,d,r,i,h,c,nr:longint; f1,f2:text; v,z:array[0..5000000] of longint;
procedure putere(x:longint);
begin p:=1;s:=0;while p*d<=x do begin p:=p*d;s:=s+x div p;end; end;
begin
assign(f1,'pascal.in');reset(f1);assign(f2,'pascal.out');rewrite(f2);read(f1,r,d);
c:=d;inc(r);d:=c;
if c<>6 then for i:=1 to r do begin if c=4 then d:=2;putere(i-1);v[i]:=s;end;
if c=6 then for i:=1 to r do begin d:=3; putere(i-1); v[i]:=s; d:=2; putere(i-1); z[i]:=s;end;
s2:=v[r]; s1:=z[r];if r mod 2=0 then nr:=r div 2 else nr:=r div 2+1;
if c<>6 then begin for i:=1 to nr do begin
if c=4 then if s2>v[i]+v[r+1-i]+1 then inc(h);
if c<>4 then if s2>v[i]+v[r+1-i] then inc(h); end;
h:=h*2; if r mod 2=1 then dec(h);end;
if c=6 then begin for i:=1 to nr do
if (s2>v[i]+v[r+1-i])and(s1>z[i]+v[r+1-i]) then inc(h); h:=h*2;end;if r mod 2=1 then dec(h);
writeln(f2,h);close(f1);close(f2);end.