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

For java,BigInteger works
Posted by Jeffrey.Xie 6 Feb 2007 05:50
Re: For java,BigInteger works
Posted by aczovo 9 Mar 2007 10:47
var
  a,b:array[1..1000]of longint;
  i,n,k,u,v,j:longint;
begin
  for i:=1 to 100 do
  begin
    a[i]:=0;
    b[i]:=0;
  end;
  readln(n);
  readln(k);
  a[1]:=k-1;
  b[1]:=k*(k-1);
  u:=1;
  v:=1;
  for i:=3 to n do
  if (i mod 2=1) then
  for j:=1 to v do
  begin
  if 9*(a[j]+b[j])>=1000000000
  then begin
  if j=v then u:=u+1;
  a[j+1]:=a[j+1]+1;
  end;
  a[j]:=9*(a[j]+b[j]) mod 1000000000
  end
  else for j:=1 to u do
  begin
  if 9*(a[j]+b[j])>=1000000000
  then begin
  if j=u then v:=v+1;
  a[j+1]:=a[j+1]+1;
  end;
  a[j]:=9*(a[j]+b[j]) mod 1000000000
  end;
  if n mod 2=1 then
  for i:=u downto 1 do
    write(a[i])
  else for i:=v downto 1 do
    write(b[i]);
end.