|
|
вернуться в форумHelp !!! Why Memory Limit ???????? const nn=100; type my=array[1..nn]of integer; var a,b,c:my; n,k:integer; function dlina(a:my):integer; var i:integer; begin i:=nn; while a[i]=0 do dec(i); dlina:=i; end; procedure mul(a:my;var c:my); var i:integer; d:integer; begin fillchar(c,sizeof(c),0); d:=dlina(a); for i:=1 to d do c[i]:=a[i]*k; for i:=1 to d do if c[i]>9 then begin inc(c[i+1],c[i] div 10); c[i]:=c[i] mod 10; end; while c[d+1]<>0 do begin inc(d); if c[d]>9 then begin c[d+1]:=c[d] div 10; c[d]:=c[d] mod 10; end; end; end; procedure slog(a,b:my;var c:my); var d1,d2,max,i:integer; begin fillchar(c,sizeof(c),0); d1:=dlina(a); d2:=dlina(b); if d1>d2 then max:=d1 else max:=d2; for i:=1 to max do begin c[i]:=c[i]+a[i]+b[i]; if c[i]>9 then begin inc(c[i+1]); c[i]:=c[i] mod 10; end; end; end; procedure init; begin assign(input,''); reset(input); readln(n); readln(k); close(input); end; procedure solve; var i:integer; s:string; begin dec(k); str(k,s); for i:=1 to length(s) do c[i]:=ord(s[length(s)-i+1])-48; for i:=2 to n do begin a:=b; b:=c; slog(a,b,c); mul(c,c); end; slog(b,c,c); end; procedure out; var i:integer; begin assign(output,''); rewrite(output); for i:=dlina(c) downto 1 do write(c[i]); close(output); end; begin init; solve; out; end. |
|
|