Pagini recente » Cod sursa (job #2816794) | Cod sursa (job #1857288) | Cod sursa (job #201094) | Cod sursa (job #1489595) | Cod sursa (job #190445)
Cod sursa(job #190445)
var f,g:text;
v,a,b,c:array[0..100000000]of longint;
n,t,aux,m,p,q,i,j:longint;
x:char;
begin
assign(f,'sarpe.in');
assign(g,'sarpe.out');
reset(f);
rewrite(g);
while not eoln(f) do
begin
inc(n);
read(f,x);
v[n]:=ord(x)-ord('0');
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)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)do
begin
inc(i);
t:=0;
if (b[i]>1)then dec(b[i]) else
begin
b[i]:=10+b[i]-1;
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;
while(t>0)do
begin
inc(m);
a[m]:=t mod 10;
t:=t div 10;
end;
t:=0;
q:=m+p-1;
for i:=1 to m do
begin
t:=0;
for j:=1 to p do
begin
inc(c[i+j-1],a[i]*b[j]+t);
t:=c[i+j-1] div 10;
c[i+j-1]:=c[i+j-1] mod 10;
end;
if (t>0)then
begin
v[i+p]:=t;
if (i+p>q)then inc(q);
end;
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;
while (t>0)do
begin
inc(n);
v[n]:=t mod 10;
t:=t div 10
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.