|
|
вернуться в форумWRONG AnSwEr # 2!!!! Where is wrong? This is MY SOLVe!!! program MEGA; {$APPTYPE CONSOLE} uses SysUtils; var i,n,k:integer; a:array[1..100] of int64; m:int64; begin read(n,k); if n=2 then begin writeln((k-1)*k); halt(0); end; if n=3 then begin writeln((k-1)*k*k-k+1); halt(0); end; a[3]:=k-1; m:=k-1; for i:=4 to n do begin m:=m*(k-1); a[i]:=a[i-1]+(i-2)*m; end; m:=k-1; for i:=1 to n-1 do m:=m*k; writeln(m-a[n]); end. Re: WRONG AnSwEr # 2!!!! I had a wrong answer in test #2 due to integer overflow. Replacing 32-bit integers with 64-bit integers helped and all tests passed (only in my solution, I didn't test yours). |
|
|