Hello coders, today we are going to solve **Nuclear Reactors CodeChef Solution** whose Problem Code is **NUKES**.

**Task**

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.

**Input Format**

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.

**Output Format**

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**

**Sample Input**

`3 1 3`

**Sample Output**

`1 1 0`

**Explanation**

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.

**Solution – Nuclear Reactors**

**C++**

#include <bits/stdc++.h> using namespace std; int main(){ int a, n ,k; cin >> a>>n>>k; int arr[k]={0}; while(a--){ arr[0]+=1; for(int i=0;i<k;i++){ if(arr[i]<=n){ break; } arr[i]=0; arr[i+1]+=1; } } for(int i=0;i<k;i++){ cout<<arr[i]<<" "; } return 0; }

**Python**

# cook your dish here A,N,k=map(int,input().split()) x=N+1 for i in range(0,k): print(A%x, end=" ") A=A//x

**Java**

/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Codechef { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int A = sc.nextInt(); int N = sc.nextInt(); int K = sc.nextInt(); int op[] = new int[K]; while(A-- > 0) { for(int i=0;i<K;i++) { if(op[i]<N) { op[i]++; break; } op[i]=0; } } for(int arr : op) { System.out.println(arr); } } }

**Disclaimer:** The above Problem **(Nuclear Reactors)** is generated by **CodeChef** but the Solution is Provided by **CodingBroz**. This tutorial is only for **Educational** and **Learning** Purpose.