|
|
вернуться в форумwrong with #8 Could anybody tell my what the test data#8 is, or tell me where my program wrong: var a,b,c:array [1..20000] of 0..9; n,k:longint; i,j:int64; procedure mul; var i,j,r,c:byte; begin c:=0; inc(j); while a[j]=0 do dec(j); i:=0; repeat inc(i); r:=a[i]*(k-1)+c; a[i]:=r mod 10; c:=r div 10; until i=(j+1); end; procedure add; var i,j,r,c:byte; begin c:=0; inc(j); while a[j]=0 do dec(j); i:=0; repeat inc(i); r:=a[i]+b[i]+c; a[i]:=r mod 10; c:=r div 10; until i=(j+1); end; begin read(n,k); fillchar(a,sizeof(a),0); fillchar(b,sizeof(b),0); fillchar(c,sizeof(c),0); a[1]:=k-1; j:=1793; i:=1; repeat inc(i); c:=a; add; mul; b:=c; until i=n; add; inc(j); while a[j]=0 do dec(j); inc(j); repeat dec(j); write(a[j]); until j=1; writeln; end. (like this one: var a,b,c:extended; n,k,i:integer; begin readln(n,k); a:=k-1; for i:=2 to n do begin c:=a; a:=(a+b)*(k-1); b:=c; end; a:=a+b; writeln(a); end.) Re: wrong with #8 Послано lain 11 сен 2007 23:31 [quote] procedure mul; var i,j,r,c:byte; begin c:=0; inc(j); while a[j]=0 do dec(j); i:=0; repeat inc(i); r:=a[i]*(k-1)+c; a[i]:=r mod 10; c:=r div 10; until i=(j+1); end; [/quote] r and others must not to be byte "r:=a[i]*(k-1)+c;" a[i]*(k-1)+c can be >255 use longint maybe Edited by author 11.09.2007 23:33 |
|
|