Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project1;
- uses
- SysUtils;
- const
- Q: QWord = 1000000000;
- type
- TLongNumber = array of QWord;
- type
- TBase = integer;
- function Invers_str(str: ansistring): ansistring;
- var
- newS: ansistring;
- i: integer;
- begin
- for i := length(str) downto 1 do
- begin
- newS += str[i];
- end;
- Result := newS;
- end;
- function invers_num(num:TLongNumber): TLongNumber;
- var i, j:integer;
- begin
- j := high(num);
- Setlength(result, length(num));
- for i := 0 to high(num) do begin
- result[j] := num[i];
- j -= 1;
- end;
- end;
- operator * (a, b: TLongNumber) ans: TLongNumber;
- var
- i, j: integer;
- s, buf, buf2: QWord;
- begin
- s := 0;
- begin
- SetLength(Result, high(a) + high(b) + 1);
- for i := 0 to high(Result) do
- begin
- Result[i] := 0;
- end;
- for i := 0 to high(b) do
- begin
- s := 0;
- for j := 0 to high(a) do
- begin
- buf := b[i] * a[j] + s + Result[i+j];
- s := buf div Q;
- Result[i+j]:=buf mod Q;
- end;
- if (s > 0) then
- begin
- if i = high(b) then
- SetLength(Result, Length(Result) + 1);
- Result[i + high(a) + 1] := s;
- end;
- end;
- end;
- end;
- function Exp(num: TLongNumber; n: integer): TLongNumber;
- var
- x: TLongNumber;
- begin
- SetLength(x, 1);
- x[0] := 1;
- while (n <> 0) do
- begin
- if (n mod 2 = 1) then
- begin
- x := x * num;
- end;
- num := num * num;
- n := n div 2;
- end;
- Result := x;
- end;
- function ToString(val: TLongNumber): ansistring;
- var i, j, count: integer;
- begin
- result := '';
- for i := high(val) downto 0 do begin
- // result += (Format(IntTostr(val[i]), ['%.9s']));
- if (length(IntToStr(val[i])) < 9) then begin
- count := 9 - length(IntToStr(val[i]));
- for j := 1 to count do Result += '0';
- end;
- Result += IntToStr(val[i]);
- end;
- i := 1;
- while result[i] = '0' do begin
- if (result = '0') then exit('0');
- Delete(result, i, 1);
- end;
- end;
- function FromString(str: ansistring): TLongNumber;
- var n, i, j, len: integer;
- buf: string;
- begin
- len := (length(str) div 9) + 1;
- SetLength(Result, len);
- n := 0;
- i:= 1;
- str := invers_str(str);
- while i <= length(str) do begin
- buf := copy(str, i, 9);
- buf := invers_str(buf);
- i += 9;
- result[n] := StrToInt(buf);
- n += 1;
- end;
- //Result := invers_num(result);
- end;
- function PowLong(s: ansistring; n: integer): ansistring;
- var
- num: TLongNumber;
- buf: TLongNumber;
- i: integer;
- begin
- if (n = 0) then
- exit('1');
- SetLength(buf, 1);
- buf[0] := 1;
- num := FromString(s);
- buf := Exp(num, n);
- Result := ToString(buf);
- end;
- var
- s: ansistring;
- n: integer;
- begin
- Assign(input, 'input.txt');
- Assign(output, 'output.txt');
- reset(input);
- rewrite(output);
- readln(s);
- Read(n);
- Writeln(PowLong(s, n));
- // writeln(length(PowLong(s, n)));
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement