Cod sursa(job #48437)

Utilizator raduzerRadu Zernoveanu raduzer Data 4 aprilie 2007 19:35:34
Problema Pascal Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.31 kb
var a,b,c:array[1..5]of longint;
    r,d,s,i,j,x,y,q,z:longint;
begin
     assign(input,'pascal.in');
     reset(input);
     assign(output,'pascal.out');
     rewrite(output);
     readln(r,d);
     for i:=2 to d do
     begin
          while d mod i =0 do
          begin
               a[i]:=a[i]+1;
               d:=d div i;
          end;
     end;
     x:=r;
     for i:=2 to 5 do
     begin
          if r>=i then
          begin
               if i=4 then b[2]:=b[2]+r div i
               else b[i]:=b[i]+r div i;
          end;
     end;
     r:=x;
     s:=0;
     for i:=1 to r do
     begin
          y:=i;
          x:=r-y;
          c[2]:=0;
          c[3]:=0;
          c[5]:=0;
          if x>=2 then c[2]:=c[2]+x div 2;
          if x>=3 then c[3]:=c[3]+x div 3;
          if x>=4 then c[2]:=c[2]+x div 4;
          if x>=5 then c[5]:=c[5]+x div 5;
          if y>=2 then c[2]:=c[2]+y div 2;
          if y>=3 then c[3]:=c[3]+y div 3;
          if y>=4 then c[2]:=c[2]+y div 4;
          if y>=5 then c[5]:=c[5]+y div 5;
          q:=0;
          if (a[2]>b[2]-c[2])and(a[2]>0) then q:=1;
          if (a[3]>b[2]-c[2])and(a[3]>0) then q:=1;
          if (a[5]>b[5]-c[5])and(a[5]>0) then q:=1;
          if q=0 then s:=s+1;
     end;
     writeln(s);
close(output);
end.