12_12_2012 Довга арифметика Печать
Добавил(а) Гісь Ігор Володимирович   
12.12.12 09:55

 

Сума довгих Довгий факторіа
var f1,f2:text;
a,b,c:array [0..100] of integer;
i,os:integer;
s:char;
begin
assign(f1,'long1.dat');
reset(f1);
while not(eoln(f1)) do begin
read(f1,s);
if s in ['0'..'9'] then begin
for i:=a[0] downto 1 do
a[i+1]:=a[i];

a[1]:=ord(s)-ord('0');
a[0]:=a[0]+1;
end;
end;

readln(f1,s);

while not(eoln(f1)) do begin
read(f1,s);
if s in ['0'..'9'] then begin
for i:=b[0] downto 1 do
b[i+1]:=b[i];

b[1]:=ord(s)-ord('0');
b[0]:=b[0]+1;
end;
end;
close(f1);

if a[0]>b[0] then c[0]:=a[0] else c[0]:=b[0];
os:=0;
for i:=1 to c[0] do begin
c[i]:=(a[i]+b[i]+os) mod 10;
os:=(a[i]+b[i]+os) div 10;
end;

if os>0 then begin c[0]:=c[0]+1;c[c[0]]:=os;end;

assign(f2,'long1.sol');
rewrite(f2);
for i:=c[0] downto 1 do write(f2,c[i]);
writeln(f2);
close(f2);
end.
program factorial_long;


{$APPTYPE CONSOLE}

var a,c:array[0..1000] of integer;
n:integer;
j,i:integer;
f:text;
des:integer;
begin
assign(f,'factor.dat'); reset(f);
readln(f,n);
close (f);
assign(f,'factor.sol');rewrite(f);
a[0]:=1;
a[1]:=1;
c[0]:=a[0];
des:=0;
for j:=1 to n do begin
des:=0;
for i:=1 to a[0] do begin
c[i]:=(a[i]*j+des) mod 10;
des:=(a[i]*j+des) div 10 ;
end;
while des>0 do begin c[0]:=c[0]+1;c[c[0]]:=des mod 10; des:=des div 10;end;
for i:=0 to c[0] do a[i]:=c[i];
for i:=c[0] downto 1 do write(f,c[i]);
writeln(f);
end;

close(f);
end.