All submissions for this problem are available.
There are K nuclear reactor chambers labelled from 0 to K-1. Particles are bombarded onto chamber 0. The particles keep collecting in the chamber 0. However if at any time, there are more than N particles in a chamber, a reaction will cause 1 particle to move to the immediate next chamber(if current chamber is 0, then to chamber number 1), and all the particles in the current chamber will be be destroyed and same continues till no chamber has number of particles greater than N. Given K,N and the total number of particles bombarded (A), find the final distribution of particles in the K chambers. Particles are bombarded one at a time. After one particle is bombarded, the set of reactions, as described, take place. After all reactions are over, the next particle is bombarded. If a particle is going out from the last chamber, it has nowhere to go and is lost.
The input will consist of one line containing three numbers A,N and K separated by spaces.
A will be between 0 and 1000000000 inclusive.
N will be between 0 and 100 inclusive.
K will be between 1 and 100 inclusive.
All chambers start off with zero particles initially.
Consists of K numbers on one line followed by a newline. The first number is the number of particles in chamber 0, the second number is the number of particles in chamber 1 and so on.
Input: 3 1 3 Output: 1 1 0
Total of 3 particles are bombarded. After particle 1 is bombarded, the chambers have particle distribution as
"1 0 0". After second particle is bombarded, number of particles in chamber 0 becomes 2 which is greater
than 1. So, num of particles in chamber 0 becomes 0 and in chamber 1 becomes 1. So now distribution is
"0 1 0". After the 3rd particle is bombarded, chamber 0 gets 1 particle and so distribution is "1 1 0" after all
particles are bombarded one by one.
|Time Limit:||0.2 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, PERL6, TEXT, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.