ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Common Board

1013 WA
Posted by I am david. Tabo. 26 May 2002 16:41
program ff;
  var
    n,i,j,k,l,t:integer;
    u0,u1,u2,a,b,c:array[0..2000] of byte;

  function max(a,b:integer):integer;
    begin
      if a>b then max:=a else max:=b;
    end;

  procedure sum(a,b:array of byte);
    begin
      l:=max(a[0],b[0]);
      fillchar(c,sizeof(c),0);
      t:=0;
      for i:=1 to l do begin
        c[i]:=(a[i]+b[i]+t) mod 10;
        t:=(a[i]+b[i]+t) div 10;
      end;
      c[0]:=l;
      if t<>0 then begin
        c[0]:=l+1;
        c[l+1]:=t;
      end;
    end;

  procedure mult(a:array of byte);
    begin
      l:=k-1;
      t:=0;
      fillchar(c,sizeof(c),0);
      for i:=1 to a[0] do begin
        c[i]:=(l*a[i]+t) mod 10;
        t:=(l*a[i]+t) div 10;
      end;
      c[0]:=a[0];
      if t<>0 then begin
        c[0]:=a[0]+1;
        c[c[0]]:=t;
      end;
    end;

  procedure solve;
    begin
      u0[1]:=1; u0[0]:=1;
      u1[1]:=k-1; u1[0]:=1;
      for j:=2 to n do begin
        sum(u0,u1);
        u2:=c;
        mult(u2);
        u2:=c;
        u0:=u1;
        u1:=u2;
      end;
    end;

  begin
    readln(n,k);
    solve;
    for i:=u2[0] downto 1 do write(u2[i]);
    writeln;
  end.

change all bytes to integers and all will works
Posted by guseva polina 27 May 2002 02:03
> program ff;
>   var
>     n,i,j,k,l,t:integer;
>     u0,u1,u2,a,b,c:array[0..2000] of byte;
>
>   function max(a,b:integer):integer;
>     begin
>       if a>b then max:=a else max:=b;
>     end;
>
>   procedure sum(a,b:array of byte);
>     begin
>       l:=max(a[0],b[0]);
>       fillchar(c,sizeof(c),0);
>       t:=0;
>       for i:=1 to l do begin
>         c[i]:=(a[i]+b[i]+t) mod 10;
>         t:=(a[i]+b[i]+t) div 10;
>       end;
>       c[0]:=l;
>       if t<>0 then begin
>         c[0]:=l+1;
>         c[l+1]:=t;
>       end;
>     end;
>
>   procedure mult(a:array of byte);
>     begin
>       l:=k-1;
>       t:=0;
>       fillchar(c,sizeof(c),0);
>       for i:=1 to a[0] do begin
>         c[i]:=(l*a[i]+t) mod 10;
>         t:=(l*a[i]+t) div 10;
>       end;
>       c[0]:=a[0];
>       if t<>0 then begin
>         c[0]:=a[0]+1;
>         c[c[0]]:=t;
>       end;
>     end;
>
>   procedure solve;
>     begin
>       u0[1]:=1; u0[0]:=1;
>       u1[1]:=k-1; u1[0]:=1;
>       for j:=2 to n do begin
>         sum(u0,u1);
>         u2:=c;
>         mult(u2);
>         u2:=c;
>         u0:=u1;
>         u1:=u2;
>       end;
>     end;
>
>   begin
>     readln(n,k);
>     solve;
>     for i:=u2[0] downto 1 do write(u2[i]);
>     writeln;
>   end.
>
>
>
THENk you. good geerl. with it i solved problem 1012 TOOOOOO
Posted by I am david. Tabo. 27 May 2002 19:04
but I think it's no good to use a not your own source to solve a problem!!!
Posted by guseva polina 29 May 2002 21:15
>