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

why wa in test 1?
Posted by zsyzhbc_china 22 Mar 2009 12:38
program t1012;
var
  a,b,n,k,i,j,l,p,q,c,d,o:longint;
  f,h:array [0..10000] of string;
  s,x,m:string;
begin
  readln(n);
  readln(k);
  str(k-1,m);
  f[0]:=m;
  val(f[0],a,b);
  str(k*a,m);
  f[1]:=m;l:=1;
  for i:=2 to n do
  begin
    a:=length(f[i-1]);
    b:=length(f[i-2]);
    if a>b then d:=a else d:=b;
    x:=f[i-1];m:=f[i-2];
    if d=a then
    for j:=a-b downto l do
    m:=concat('0',m);
    if d=b then
    for j:=b-a downto l do
    x:=concat('0',x);
    for j:=d downto l do
    begin
      val(x[j],p,o);
      val(m[j],q,o);
      b:=p+q+c;
      c:=b div 10;
      q:=b mod 10;
      str(q,h[j]);
      if j=l then if c>0 then begin dec(l);str(c,h[l]); end;
      p:=0;q:=0;
    end;
    c:=0;
    for j:=l to d do
    s:=concat(s,h[j]);
    l:=1;
    for j:=d downto l do
    begin
      val(s[j],p,o);
      b:=p*9+c;
      c:=b div 10;
      q:=b mod 10;
      str(q,h[j]);
      if j=l then if c>0 then begin dec(l);str(c,h[l]); end;
      p:=0;q:=0;
    end;
    c:=0;
    s:='';
    for j:=l to d do
    s:=concat(s,h[j]);
    l:=1;
    f[i]:=s;
    s:='';
  end;
  writeln(f[n-1]);
end.