//длинная арифметика
begin
var a := '123456789123456789';//ReadString();
var b := '123456789123456789123';//...
var l := Abs(a.Length - b.Length);
var source := l*'0';
if a.Length > b.Length then
insert(source, b, 1)
else
insert(source, a, 1);
var s := '';
var mem := 0;
for var i:=a.Length downto 1 do
var c := a[i].ToDigit + b[i].ToDigit + mem;
mem := c div 10;
insert((c mod 10).ToString, s, 1)
end;
if (mem > 0) then insert('1', s, 1);
s.Println;
end.
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
//длинная арифметика
begin
var a := '123456789123456789';//ReadString();
var b := '123456789123456789123';//...
var l := Abs(a.Length - b.Length);
var source := l*'0';
if a.Length > b.Length then
insert(source, b, 1)
else
insert(source, a, 1);
var s := '';
var mem := 0;
for var i:=a.Length downto 1 do
begin
var c := a[i].ToDigit + b[i].ToDigit + mem;
mem := c div 10;
insert((c mod 10).ToString, s, 1)
end;
if (mem > 0) then insert('1', s, 1);
s.Println;
end.
var a := '123456789123456789'.ToBigInteger;
var b := '123456789123456789123'.ToBigInteger;
Print(a + b)
end.