avatar
Untitled

Guest 2.3K 19th Jan, 2019

uses crt;
type bigNum = string;
var n:bigNum;

function tong(a,b:bigNum):bigNum;
var kq:bigNum; i,s,carry:longint;
begin carry:=0; kq:='';
  while length(a) < length(b) do a:='0'+a;
  while length(b) < length(a) do b:='0'+b;
  for i:=length(a) downto 1 do
    begin
      s:=ord(a[i])+ord(b[i])-96+carry;
      carry:= s div 10;
      kq:=chr(s mod 10 + 48) + kq;
    end;
  if carry > 0 then kq:='1'+kq; exit(kq);
end;

function tich(a,b:bigNum):bigNum;
var m,i,j:longint; sum,tmp:bigNum;
begin
  m:=-1; sum:='';
  for i:=length(b) downto 1 do
    begin
      inc(m);
      tmp:='';
      for j:=1 to ord(b[i])-48 do tmp:=tong(tmp,a);
      for j:=1 to m do tmp:=tmp+'0';
      sum:=tong(tmp,sum);
    end; exit(sum);
end;

function bigDiv(a:bigNum;b:longint):bigNum;
var hold,i,s:longint; kq:bigNum;
begin hold:=0; kq:='';
  for i:=1 to length(a) do
    begin
      hold:=hold*10 + ord(a[i])-48;
      s:=hold div b;
      hold:=hold mod b;
      kq:=kq+chr(s + 48);
    end;
  while (length(kq) > 1) and (kq[1] = '0') do delete(kq,1,1);
  exit(kq);
end;

function bigMod(a:bigNum;b:longint):longint;
var hold,i:longint;
begin hold:=0;
  for i:=1 to length(a) do
    hold:=(hold*10 + ord(a[i]) - 48) mod b;
  exit(hold);
end;
Pascal
Description

No description

To share this paste please copy this url and send to your friends
RAW Paste Data