| 
 | 
back to boardPlease help!!! (almosat correct program inside) Can anyone tell me what is wrong with this program? I get WA. I used bignums, but instead of representing the numbers in base 10, i did it in base 1000. I checked all my answers with my slow program (which got TLE) and they seem to be right. Here's the code:     type bignum=array[0..35000] of longint; var a,b:bignum;     n,i,j:longint; procedure subs(var x,y:bignum); var i:longint; begin   for i:=x[0] downto 1 do       if i<=y[0] then begin       x[i]:=x[i]-y[i];       if x[i]<0 then begin          dec(x[i+1]); x[i]:=x[i]+1000;          end;       end;   while x[x[0]]=0 do dec(x[0]); end; procedure square(a:bignum; var b:bignum); var i,j:longint; begin   fillchar(b,sizeof(b),0);   b[0]:=2*a[0];   for i:=1 to a[0] do       for j:=1 to a[0] do           b[i+j-1]:=b[i+j-1]+a[i]*a[j];    for i:=1 to b[0]-1 do        if  b[i]>999 then begin            b[i+1]:=b[i+1]+b[i] div 1000;            b[i]:=b[i] mod 1000;            end;    if b[b[0]]=0 then dec(b[0]); end; begin   readln(n);   fillchar(a,sizeof(a),0);   a[0]:=1; a[1]:=2;   writeln('2');   for i:=2 to n do begin       square(a,b);       subs(b,a);       inc(b[1]);       k:=1;       while b[k]>999 do begin             b[k]:=b[k] mod 1000;             inc(k);             inc(b[k]);             end;       if k>b[0] then inc(b[0]);       a:=b;       for j:=a[0] downto 1 do begin           if (j<>a[0]) and (a[j]<100) then write('0');           if (j<>a[0]) and (a[j]<10) then write('0');           write(a[j]);           end;       writeln;       end; end. Re: Here is my AC solution,I think it can help you Posted by  ACer 4 Jul 2003 20:49 const max=30000; type arr=array[1..max] of longint; var    c,a,b:arr;      i,j,n,k,l,t:longint;   procedure chen; var i,j,k:longint; begin      i:=max;k:=max;      while a[i]=0 do dec(i);      while b[k]=0 do dec(k);      l:=i+k;      repeat            j:=0;            repeat                  inc(j);                  c[i+j-1]:=c[i+j-1]+a[i]*b[j];                  until j>=k;                  dec(i);            until i<=0;   end; begin      readln(n);a[1]:=2;b[1]:=1;      writeln(2);      l:=1;      for i:=2 to n do begin          fillchar(c,sizeof(c),0);          chen;          a:=c;          for j:=1 to max do              if a[j]>=100 then begin                 a[j+1]:=a[j+1]+a[j] div 100;                 a[j]:=a[j] mod 100;                 end;          b:=a;          inc(a[1]);j:=1;          while a[j]>=100 do begin                 a[j+1]:=a[j+1]+a[j] div 100;                 a[j]:=a[j] mod 100;                 end;          k:=maX;          while a[k]=0 do dec(k);          write(a[k]);          for j:=k-1 downto 1 do          if a[j]=0 then write('00')          else          begin           t:=10;           while a[j]<t do           begin                write('0');                t:=t div 10;                  end;                write(a[j]);                end;          writeln;          end;   end. Thank you! Thank you, I got AC! Couldn't find the bug in my first program, it gave the same results as yours up to test 10, after tha they were to big to check, but I rewrote it from scrap and got AC!  |  
  | 
|