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 1013. K-based Numbers. Version 3

a program
Posted by math404_3140 12 Aug 2006 13:35
tell me wht doesn't this program work? or at least tell me an example that my program doesn't give us the right answer

var
       l,n,k :integer;
       sum   :longint;

function c(a,b:integer):integer;
   var
       i,a1,b1,a1b1:integer;
   begin
       a1:=1;
       for i:=1 to a do
          a1:=a1*i;
       b1:=1;
       for i:=1 to b do
          b1:=b1*i;
       a1b1:=1;
       for i:=1 to a-b do
          a1b1:=a1b1*i;
       c:=a1 div (b1*a1b1);
   end;

function power(r,s:integer):integer;
   var
       j,rs:integer;
   begin
       rs:=1;
       for j:=1 to s do
           rs:=rs*r;
       power:=rs;
   end;



begin
     readln(n,k);
     l:=-1;
     while 2*l<=n do
     begin
           inc(l);
           inc(sum,(c(n-l,l)*power(k-1,n-l)));
     end;
     writeln(sum);
end.
Re: a program
Posted by Todor Tsonkov 12 Aug 2006 20:11
Try with Big Numbers, no standart type will pass this problem as far as I remember,otherwise the idea I think is  clear