There are K nuclear reactor Chambers labeled from 0 to K-1. participant are bombarded onto Chamber 0. the participating keep collecting in the Chamber 0. however if at any time, there are more than N participant 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 participants in the current chamber will be destroyed and same continues till no chamber has number of participant greater than N. given k, n and the total number of particles bombarded (A), find the final distribution of particles in the K chambers. participant 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.
Input
The input will consist of one line containing three numbers A, N and K separated by spaces.
A will be between 0 and 1000000000 aggressive.
N will be between 0 and 100 aggressive.
K will be between 1 and 100 aggressive.
All Chambers start off with zero participates initially.
Output
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.
Example
Input:3 1 3Output:1 1 0
It is easy to find a rule and use it to solve the problem, rather than simulate the process.
#pragma once#include <vector>#include <string>#include <algorithm>#include <stack>#include <stdio.h>#include <iostream>using namespace std;int NuclearReactors(){int A, N, K;cin>>A>>N>>K;N++;int *tbl = new int[K];int t = A;for (int i = 0; i < K; i++){tbl[i] = t % N;t /= N;}for (int i = 0; i < K; i++){printf("%d ", tbl[i]);}printf("\n");delete [] tbl;return 0;}