ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1153. Supercomputer

Whi crash. helppppppp. see program
Posted by I am david. Tabo. 17 Oct 2002 22:52
type
 long = record
              a:array[1..1300]of byte;
              l:integer;
        end;
var h,i,c:integer;
    ch:Char;
    a,tmp:long;

    procedure add2(var a:long;b:longint);
var l,c,k,i:longint;
begin
  k:=b;
{  if a.l>b.l then l:=a.l else l:=b.l;}l:=a.l;
  for i:=1 to l do
  begin
    c:=a.a[i];
    a.a[i]:=(c+k)mod 10;
    k:=(c+k)div 10;
  end;
{  a.l:=i;}
  while k<>0 do
  begin
    inc(a.l);
    a.a[a.l]:=K mod 10;
    K:=K div 10;
  end;
end;

procedure add(var a,b:long);

var l,c,k,i:integer;
begin
  k:=0;
  if a.l>b.l then l:=a.l else l:=b.l;
  for i:=1 to l do
  begin
    c:=a.a[i];
    a.a[i]:=(c+b.a[i]+k)mod 10;
    k:=(c+b.a[i]+k)div 10;
  end;
  a.l:=l;
  if k<>0 then
  begin
    inc(a.l);
    a.a[a.l]:=K;
  end;
end;

procedure sub(var a,b:long);
var l,c,k,i:integer;
begin
  k:=0;
  if a.l>b.l then l:=a.l else l:=b.l;
  for i:=1 to l do
  begin
    c:=a.a[i];
    a.a[i]:=(c-b.a[i]+k+10)mod 10;
{    k:=(c-b.a[i]+k)div 10;}
    if (c-b.a[i]+k)<0 then k:=-1 else k:=0;
  end;
  a.l:=l;
{  if k<>0 then
  begin
    inc(a.l);
    a.a[a.l]:=K;
  end;}
  i:=a.l;
  for i:=a.l downto 1 do if a.a[i]<>0 then break;
  a.l:=i;
end;

procedure mul_i(var a:long;b:longint);
var k:longint;c,i:integer;
begin
  k:=0;
  for i:=1 to a.l do
  begin
    c:=a.a[i];
    a.a[i]:=(c*b+k)mod 10;
    k:=(c*b+k)div 10;
  end;
{  a.l:=i;}
  while k<>0 do
  begin
    inc(a.l);
    a.a[a.l]:=K mod 10;
    k:=k div 10;
  end;
  i:=a.l;
  for i:=a.l downto 1 do if a.a[i]<>0 then break;
  a.l:=i;
end;

procedure mul(var a,b:long);
var tmp,_a:long;
    i,j:integer;
begin
  fillchar(tmp,sizeof(tmp),0);
  for i:=1 to b.l do
  begin
    _a:=a;
    mul_i(_a,b.a[i]);
    for j:=_a.l downto 1 do _a.a[j+i-1]:=_a.a[j];
    for j:=1 to i-1 do _a.a[j]:=0;
    _a.l:=_a.l+i-1;
    add(tmp,_a);
  end;
  a:=tmp;
end;

function cmp(var a,b:long):integer;
var i:integer;
begin
 if a.l>b.l then cmp:=+1 else if a.l<b.l then cmp:=-1
 else
 begin
   for i:=a.l downto 1 do if a.a[i]>b.a[i] then
   begin
     cmp:=+1;exit;
   end
   else if a.a[i]<b.a[i] then
   begin
     cmp:=-1;exit;
   end;
   cmp:=0;
 end;
end;

procedure _sqrt(var a:long);
var tmp,ost,tmp2:long;
    r:long;
    tek,i,h,j:integer;
    c:byte;
begin
  h:=0;
  fillchar(tmp,sizeof(tmp),0);
  fillchar(ost,sizeof(tmp),0);
  if a.l mod 2 = 0 then tek:=a.l-1 else tek:=a.l;
  while true do
  begin
    for i:=tmp.l downto 1 do tmp.a[i+1]:=tmp.a[i];
    inc(tmp.l);
    mul_i(ost,100);
    add2(ost,a.a[tek+1]*10+a.a[tek]);
    for j:=0 to 9 do
    begin
      i:=j;
      tmp.a[1]:=i;tmp2:=tmp;
      mul_i(tmp2,i);
      if cmp(ost,tmp2) = -1 then
      begin
        dec(i);
        break;
      end;
    end;
    inc(h);r.a[h]:=i;
    tmp.a[1]:=i;tmp2:=tmp;
    mul_i(tmp2,i);
    sub(ost,tmp2);
    add2(tmp,i);
    tek:=tek-2;
    if tek<0 then break;
  end;
  r.l:=h;
  for i:=1 to h div 2 do
  begin
    c:=r.a[i];r.a[i]:=r.a[h-i+1];r.a[h-i+1]:=c;
  end;
  a:=r;
end;

procedure _div(var a:long);
var k,i:longint;
begin
  K:=0;
  for i:=a.l downto 1 do
  begin
    K:=K*10+a.a[i];
    if not((K div 2=0)and(i = a.l)) then write(K div 2);
    K:=K mod 2;
  end;
  writeln;
{  if K = 0 then}
end;
begin
{  assign(input,'1153.dat');reset(input);}
  while not seekeof do
  begin
    inc(H);
    read(ch);
    a.a[h]:=ord(ch)-ord('0');
  end;
  for i:=1 to h div 2 do
  begin
    c:=a.a[i];a.a[i]:=a.a[h-i+1];a.a[h-i+1]:=c;
  end;
  a.l:=h;
  mul_i(a,8);
  tmp.a[1]:=1;tmp.l:=1;
  add(a,tmp);
  _sqrt(a);
  sub(a,tmp);
  _div(a);
end.