|
|
back to boardI have TLE on test#9. What I have to do? {$APPTYPE CONSOLE} uses SysUtils, Math; Function Sum(f1,f2:string):string; var f,ff,a:string; i,n,p,s:integer; begin n:=Max(length(f1),length(f2)); if n=length(f2) then begin f:=f2;ff:=f1;end else begin f:=f1;ff:=f2;end; while length(f)<>Length(ff) do ff:='0'+ff; p:=0; a:=''; s:=0; for i:=n downto 1 do begin s:=StrToInt(f[i])+StrToInt(ff[i])+p; Str(s,a); f[i]:=a[length(a)]; p:=s div 10; a:=''; end; if p<>0 then f:=IntToStr(p)+f; Result:=f; end; Function Mult(k:integer;f1,f2:string):string; var f,a:string; i,s,p:integer; begin f:=Sum(f1,f2); p:=0; a:=''; s:=0; for i:=length(f) downto 1 do begin s:=StrToInt(f[i])*k+p; Str(s,a); f[i]:=a[length(a)]; p:=s div 10; a:=''; end; if p<>0 then f:=IntToStr(p)+f; Result:=f; end; var n,k,i:integer; f1,f2,f:string; begin readln(n); readln(k); f1:=IntToStr(k-1); f2:=IntToStr(StrToInt(f1)*k); for i:=2 to n do begin f:=Mult(k-1,f1,f2); f1:=f2; f2:=f; end; writeln(f1); end. Edited by author 30.03.2008 23:29 Re: I have TLE on test#9. What I have to do? Posted by iama 25 Jan 2012 14:38 Obviously, write normal bignum arithmetic. |
|
|