Pagini recente » Cod sursa (job #963936) | Cod sursa (job #1940525) | Cod sursa (job #144040) | Cod sursa (job #2829348) | Cod sursa (job #190433)
Cod sursa(job #190433)
var f,g:text;
v,a,b,c:array[0..100000000]of longint;
n,aux,m,p,q,t,i,j:longint;
begin
assign(f,'sarpe.in');
assign(g,'sarpe.out');
reset(f);
rewrite(g);
while not eoln(f) do
begin
inc(n);
read(f,v[n]);
end;
if (n=1)and(v[1]=1)then write(g,1)else
begin
for i:=1 to n div 2 do
begin
aux:=v[i];
v[i]:=v[n+1-i];
v[n+1-i]:=aux;
end;
for i:=1 to n do a[i]:=v[i];
for i:=1 to n do b[i]:=v[i];
p:=n;
m:=n;
if (a[1]>=1)then dec(a[1]) else
begin
a[1]:=9;
t:=1;
end;
i:=1;
while (t=1)and(i<m-1)do
begin
inc(i);
t:=0;
if (a[i]>0)then dec(a[i]) else
begin
a[i]:=9;
t:=1;
end;
end;
if (t=1)then dec(m);
t:=0;
if (b[1]>1)then dec(b[1],2)else
begin
b[1]:=10+b[1]-2;
t:=1;
end;
i:=1;
while (t=1)and(i<p-1)do
begin
inc(i);
t:=0;
if (b[i]>1)then dec(a[i]) else
begin
b[i]:=10+b[i]-2;
t:=1;
end;
end;
if (t=1)then dec(p);
t:=0;
for i:=1 to m do
begin
a[i]:=a[i]*2+t;
t:=a[i] div 10;
a[i]:=a[i] mod 10;
end;
if (t>0)then
begin
inc(m);
a[m]:=t;
end;
t:=0;
q:=m+p-1;
for i:=1 to m do
for j:=1 to p do
inc(c[i+j-1],a[i]*b[j]);
for i:=1 to q do
begin
inc(c[i],t);
t:=c[i]div 10;
c[i]:=c[i] mod 10;
end;
if (t>0)then
begin
inc(q);
c[q]:=t;
end;
t:=0;
for i:=1 to n do
begin
v[i]:=v[i]*4+t;
t:=v[i] div 10;
v[i]:=v[i] mod 10;
end;
if (t>0)then
begin
inc(n);
v[n]:=t;
end;
t:=0;
if (q>n)then n:=q;
for i:=1 to n do
begin
v[i]:=v[i]+c[i]+t;
t:=v[i] div 10;
v[i]:=v[i] mod 10;
end;
if (t>0)then
begin
inc(n);
v[n]:=t;
end;
for i:=n downto 1 do write(g,v[i]);
end;
close(f);
close(g);
end.