function out = end89_fast(in)

while (in~=1 & in~=89)
    ss = 0;
    while(in > 0)
       digit = mod(in,10);
       ss = ss + digit*digit;
       in = (in-digit) / 10;
    end
    in = ss;
end

if in==89
    out = true;
else
    out = false;
end

end
