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 1009. K-based Numbers

Kolesnikov_Aleksey***Barnaul*** WRONG AnSwEr # 2!!!! [1] // Problem 1009. K-based Numbers 18 Sep 2007 09:55
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.
Moytrage Re: WRONG AnSwEr # 2!!!! // Problem 1009. K-based Numbers 11 Jan 2014 22:43
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).