const
nnn=777;
type
ax=record
a:array[1..nnn] of integer;
l:integer;
end;
var
i,j:integer;
c:char;
a0,a1{out},a2{in},a3{try}:ax;
function square(init:ax):ax;
var
i,j,k,temp:integer;
s,t:ax;
begin
s:=init;
t.l:=1;
for j:=1 to 6 do
begin
for i:=1 to nnn do t.a[i]:=0;
t.l:=1;
for i:=1 to init.l do
begin
k:=0;
temp:=0;
repeat
inc(k);
inc(t.a[k+i-1],init.a[i]*s.a[k]+temp);
temp:=(t.a[k+i-1]) div 10;
t.a[k+i-1]:=t.a[k+i-1] mod 10;
until (k>=s.l) and (temp=0);
if (k+i-1)>t.l then t.l:=(k+i-1);
end;
s:=t;
end;
square:=t;
end;
function aBIGb(a,b:ax):integer;
var
i:integer;
begin
if a.l>b.l then exit(1);
if a.l<b.l then exit(-1);
for i:=a.l downto 1 do
begin
if a.a[i]>b.a[i] then exit(1);
if a.a[i]<b.a[i] then exit(-1);
end;
exit(0);
end;
function tryitO(k:integer):integer;
var
o,m,i:integer;
begin
for i:=0 to 8 do
begin
a3.a[k]:=i;
m:=aBIGb(square(a3),a2);
a3.a[k]:=i+1;
o:=aBIGb(square(a3),a2);
if (m<o) and (o<>0) then exit(i);
end;
exit(9);
end;
begin
a1.l:=0;
a2.l:=0;
for i:=1 to nnn do a1.a[i]:=0;
for i:=1 to nnn do a2.a[i]:=0;
repeat
read(c);
inc(a1.l);
a1.a[a1.l]:=ord(c)-ord('0');
until eoln;
for i:=1 to a1.l do
a2.a[i]:=a1.a[a1.l-i+1];
a2.l:=a1.l;
for j:=(nnn div 7) downto 1 do
begin
a3.l:=j;
a3.a[j]:=1;
if (aBIGb(square(a3),a2)=-1) or (aBIGb(square(a3),a2)=0) then break;
a3.a[a3.l]:=0;
end;
for i:=j downto 1 do
a3.a[i]:=tryitO(i);
for j:=a3.l downto 1 do
write(a3.a[j]);
end.
如果在其中忽略掉111位的答案的话,最后一个点就过了,如果就像上面一样,最后一个点就是29,很奇怪那!