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

explanation of the algorithm
Posted by capoeirista 13 Mar 2005 18:28
a[0] := 1; a[1] := k-1;
a[i] := (k-1)*(a[i-1] + a[i-2]);

why? could someone explain it?

thanks a bunch!!
Re: explanation of the algorithm
Posted by popolzen 13 Mar 2005 21:16
1. I do not really understand why a[0]=1
2. My assumptions were a[1]=k-1 and a[2]=k*(k-1). (It fits for your assumptions)
3. Anyway... for any k and n:
   a. First digit is nonzero => Quantity of possible first digits k-1. Multiplying it by a[n-1] we have (k-1)*a[n-1]. Requirements are satisfied because a[n-1] numbers have leading nonzero also.
   b. First digit nonzero, second - zero, then a[n-2] numbers that are leading with nonzero again. (k-1)*a[n-2].
   c. As result (k-1)*(a[n-1]+a[n-2])

Edited by author 13.03.2005 21:17
Re: explanation of the algorithm
Posted by capoeirista 14 Mar 2005 00:07
thank you very much indeed!