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 1012. K-based Numbers. Version 2

Here is my program but why it is wrong?
Posted by carol_m1 18 Jun 2003 20:09
program knumber;
var k,n,i,t:integer;
    a,b,c:array[1..2000] of integer;
procedure multiply;
var i,g:longint;
begin
  g:=0;
  for i:=1 to t do
  begin
    b[i]:=b[i]+a[i]+g;
    g:=b[i] div 10;
    b[i]:=b[i] mod 10;
  end;
  if g<>0 then
  begin
    inc(t);
    b[t]:=g;
  end;
  g:=0;
  for I:=1 to t do
  begin
    b[i]:=b[i]*(k-1)+g;
    g:=b[i] div 10;
    b[i]:=b[i] mod 10;
  end;
  while g<>0 do
  begin
    inc(t);
    b[t]:=g mod 10;
    g:=g div 10;
  end;
end;
begin
  readln(n);
  readln(k);
  a[1]:=1;
  t:=0;i:=k-1;
  while i>0 do
  begin
    inc(t);
    b[t]:=i mod 10;
    i:=i div 10;
  end;
  for i:=2 to n do
  begin
    c:=b;
    multiply;
    a:=c;
  end;
  for i:=t downto 1 do write(b[i]);
  writeln;
end.