CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Practice(easy) » Nuclear Reactors

Nuclear Reactors

Problem code: NUKES

  • Submit
  • All Submissions

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.

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

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 3
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.


Author: admin
Date Added: 15-07-2009
Time Limit: 1 sec
Source Limit: 50001 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

piyush_ramavat @ 22 Jul 2009 06:29 AM

it doesn't take java file. correctly.

i mean. i have tested this program but Judge fails for all testcases.

im not sure whether it is giving inputs correctly..

please provide some examples for submitting a code.
i.e. give a sample java file which takes input and prints values.

admin 2 @ 22 Jul 2009 06:27 PM

http://www.codechef.com/help/ You will find that information here.

karthikj @ 23 Jul 2009 12:35 AM

Hi,
no matter what optimization i do for my java code, i am not able to complete 2 test cases of yours withing the time limit.
can some one help me with this.

-karthik

admin 2 @ 23 Jul 2009 12:59 AM

What is the complexity of your solution?

atulbansal128 @ 23 Jul 2009 04:21 AM

I have a O(log(A)) solution but still it is giving time limit exceeded. i cant believe it.

atulbansal128 @ 23 Jul 2009 04:25 AM

oh I was assuming multiple input line. now its fine.

karthikj @ 23 Jul 2009 03:34 PM

@Directi Admin:
my algorithm works in 0(n), in the worst case for my implementation.
still i am not able to write within time for one of the test cases.

can i get the test data for that test case.

Thx.
-karthik

admin 2 @ 23 Jul 2009 06:37 PM

An O(n) algorithm won't work. You need a better complexity for it to pass.

shaileshpandit @ 26 Jul 2009 09:35 PM

hi, please check my solutions in java and c . both have same algorithm but yet java solution takes 1.95 s and c takes 0 s. are there any plans to remove this biasing?
basically are u calling the .class file from some script and measure how much script takes or u calling the static function from already running class and measuring how much the function took?
more precisely does the time include starting time of jvm or it is the more time taken by jvm for executing same instructions?

chiragkapasi @ 30 Jul 2009 08:51 PM

I feel there is something seriously wrong........Even with the maximum inputs my code works perfectly fast....still i am getting time limit exceeded error.........any other way to measure the time.......plz suggest

admin 2 @ 30 Jul 2009 09:08 PM

One simple way would be to check the complexity and then check if it is such that the implementation would work in time. You can try executing the code locally for the maximum sized test case and see how much time it takes.

chiragkapasi @ 30 Jul 2009 11:41 PM

i have tried it on my local pc with maximum input say 1000000000 100 100 on eclipse.....and i feel it hardly takes a second or so..........

chiragkapasi @ 30 Jul 2009 11:44 PM

And how can i check the complexity of my solution............

admin 2 @ 31 Jul 2009 01:49 AM

The complexity of your code is of a magnitude higher than O(A) and A can be as large as 10^9. You need to reduce the complexity.

vscool22 @ 6 Aug 2009 05:39 PM

I have tested my code with various test cases. It is showing correct results. But it is showing wrong answer at your end with all your test cases. Please check whether I am using Input and output correctly.
Should I display - Input : ...... next line Output : .... or just the Input values and in the next line just the output values..?

admin 2 @ 6 Aug 2009 06:43 PM

You don't need to display the input again. Just the output as specified in the problem statement. It seems you already have got this problem accepted.

I am unable to submit the

setugupta @ 18 Aug 2009 04:29 PM
I am unable to submit the solution to this problem. It says "The solution to this problem cannot be submitted now." May I know what has happened?

Submissions for this problem

admin @ 18 Aug 2009 04:34 PM

Submissions for this problem will be made available after some days.

when will we be able to

rosyish @ 21 Aug 2009 10:13 PM
when will we be able to submit the solution to this problem ??

Why can't we submit answers

piyush @ 29 Aug 2009 08:34 PM

Why can't we submit answers to this problem ?

Submissions will be enabled

admin @ 31 Aug 2009 01:40 PM

Submissions will be enabled soon.

 why has the problem been

phoenix24 @ 1 Sep 2009 01:24 AM

 why has the problem been removed ?

 HI,   I was working on this

tapan.ghia @ 1 Sep 2009 01:26 AM

 HI,

 

I was working on this problem:

http://www.codechef.com/problems/NUKES/

 

I am not able to submit my solution. Is the Nuclear Reactor problem removed?

The problem will be up soon.

admin @ 1 Sep 2009 01:54 PM

The problem will be up soon. Sorry for the inconvenience

Hi I am getting a wrong

Recca @ 21 Feb 2010 01:31 PM

Hi

I am getting a wrong answer for the case 10^9. what could be the possible problems? I think that the code I have implemented is correct.

The ID of my code is 190634.

Recca @ 21 Feb 2010 01:32 PM

The ID of my code is 190634.

I am getting a SIGFPE

shubh09 @ 19 May 2010 12:56 AM

I am getting a SIGFPE (Floating Point Exception) for the case 10^9. Also, the answers for all the other test cases were correct. How to deal with this??

Also, when I submitted the solution, it showed the results for different values of N, which according to me, should be A.

Regarding SIGFPE, please

shubh09 @ 21 May 2010 10:09 PM

Regarding SIGFPE, please don't bother anyone. Looks like C was assigning 0 to the variables that went outside the range of 'int'. Division by that variable was giving the Floating Point Exception.

@ADMIN PLZ HELP I GET SIGFPE

ChunChun @ 3 Jun 2010 06:22 PM

@ADMIN

PLZ HELP

I GET SIGFPE for A = 10^9.

BUT WHY I CAN'T SEE.

Just have a look, i've tried a lot :|

http://www.codechef.com/viewsolution/250042

@ Admin I am able to pass all

anupam328 @ 7 Jun 2010 03:37 AM

@ Admin

I am able to pass all the test cases except the third one. I have tried but I am unable to make out why, Please help. :)

oh! i got it!!

anupam328 @ 7 Jun 2010 03:42 AM

oh! i got it!!

got mine ass blown off in

AnoopNarang @ 13 Jun 2010 01:25 PM

got mine ass blown off in such a easy question.

tips for other people:

1)try to use log function.

2)take care of special case n=0

@ admin My code runs

navin9876 @ 12 Aug 2010 04:20 AM

@ admin My code runs successfully on my system....bt gives wrong answer whn i submit it here.

 

Am i too bad in algorithms or

tokyo_312 @ 27 Aug 2010 12:48 AM

Am i too bad in algorithms or am I correct in thinking that there is an O(K) solution to this problem?

ADMIN,   m get this error

nirajkant @ 21 Sep 2010 08:56 PM

ADMIN,

 

m get this error many times on submitting wht does this mean

:( internal error occurred in the system.


ADMIN here is my code m

nirajkant @ 21 Sep 2010 09:08 PM

ADMIN

here is my code m getting :( internal error occurred in the system on submitting .

http://www.codechef.com/viewsolution/335549

 

any suggestion what might be th reason ..

ya admin  me 2 getting the

nntnag17 @ 21 Sep 2010 10:03 PM

ya admin  me 2 getting the same result

:( internal error occurred in the system on submitting .

plzz help

Hi, on submitting my

nntnag17 @ 22 Sep 2010 12:34 AM
Hi, on submitting my solution to this problem ,i m getting 7 out of 8 cases right but on 8th case i am getting SIGSEGV error,here is what i get Test Approx_N_value Result (time) 1 10 accepted (0.00s) 2 10 accepted (0.00s) 3 10 accepted (0.00s) 4 10000 accepted (0.00s) 5 10000000 accepted (0.00s) 6 1000000000 accepted (0.00s) 7 100000000 accepted (0.00s) 8 100 runtime error (SIGSEGV) (0.00s) plzz help me with this ,what can be the problem

got it atlast :) i was

nntnag17 @ 22 Sep 2010 12:57 AM
got it atlast :) i was missing the case whn N=0 :D

ADMIN here is my code m

nirajkant @ 22 Sep 2010 08:33 AM
ADMIN here is my code m getting :( internal error occurred in the system on submitting . http://www.codechef.com/viewsolution/335549 still getting same error . admin pls consider and responce.

When I had executed the code

rkjha @ 25 Oct 2010 03:07 AM

When I had executed the code on my system it took 0.1 sec but after submitting here I got "Time Limited Exceeded", 2.85 sec when A = 10^9 .... http://www.codechef.com/viewsolution/364999

There is more than one

triplem @ 29 Oct 2010 01:44 PM

There is more than one possible test case with A = 10^9. Have you tried N=1 and K=100?

  //rishabh

dcerishabh @ 30 Dec 2010 11:11 PM

 

//rishabh jain

#include<iostream>

#include<cstdio>

using namespace std;

 

int main()

{

int a,n,k;

cin>>a>>n>>k;

for(int i=0;i<k;i++)

{

cout<<a%(n+1);

a=a/(n+1);

}

system("pause");

return 0;

}

my code is returning wrong answer on problem for nuclear reactor
please check the code

Your code gives the wrong

triplem @ 31 Dec 2010 02:34 AM

Your code gives the wrong answer for the sample input. Read the FAQ if you don't know how to test your code.

@stephen : i'v tried a lot. I

anantc @ 25 Feb 2011 06:30 PM

@stephen : i'v tried a lot. I can't point out any error in my logic.Codechef still says my solution is incorrect :/

Please help.

#include<stdio.h>

using namespace std;

int main()

{

long int a,pow;

int n,k,i=0,q=0,g,b,t;

scanf("%ld",&a);

scanf("%d",&n);

scanf("%d",&k);

 

while(i<k&&n!=0) {

q=0;

pow=(n+1);

while(q<(i-1)){

 

pow=(n+1)*pow;

if(pow>a){break;}

q++;

}

 

g=(a/pow);

b=(n+1);

t=g%b;

printf("%d ",t);

i++;

}

i=0;

if(n==0){while(i<k){printf("0 ");i++;}}

 

return 0;

 

}

 

i don't get it!!! What's the

abhi6691 @ 11 Aug 2011 08:27 PM
i don't get it!!! What's the algorithm???

@ admin where is the problem

navin25 @ 14 Aug 2011 08:39 PM
@ admin where is the problem in my code as for only 1 condition it is giving error.. for all others it is accepted?

http://www.codechef.com/views

navin25 @ 17 Aug 2011 05:16 PM
http://www.codechef.com/viewsolution/625658

dear admin, i have been using

moody @ 22 Aug 2011 02:41 AM
dear admin, i have been using scanner for my inputs which as you say have proven to be very slow... The problem is that i do not know how to input more than one value in the same line with BufferedReader. Would you plz teach me.. thanks :)

dear admin my code is giving

ankurnit @ 27 Aug 2011 09:12 PM
dear admin my code is giving wrong answer for input 10 but for other inputs it is chowing accepted.plz can you check my code http://www.codechef.com/viewsolution/637461

convert a number to ny base!

nitin_surana @ 30 Aug 2011 03:58 AM
convert a number to ny base! good messed up situation

@rishabh: i think you should

rahul09it64 @ 8 Sep 2011 03:35 PM
@rishabh: i think you should not use iostreams header in c as per codechef..

It says TLE for N values

s1aurabhpal_7 @ 7 Oct 2011 02:34 PM
It says TLE for N values around 100... plz help my solution is http://www.codechef.com/viewsolution/691137

Hi Admin, can you check my

sachin_nagar @ 21 Oct 2011 11:13 AM
Hi Admin, can you check my code and tell me where is mistake , actually it is running good. but showing wrong answer when i submit it.. http://www.codechef.com/viewsolution/707929

Hi! somebody please tell

monikadaryani @ 31 Oct 2011 07:01 PM
Hi! somebody please tell doesnt itoa work here??

the result list of top

gkcoder @ 5 Jan 2012 02:31 AM
the result list of top submission shown on right side is not correct. why i always get memory used as 1.6M . Then i tried to submit 1st solution of "muthu m" which is now taking 0.01s and memory used as 1.6M then why that solution is on the top..????

There is an O(k) solution. An

prabhakaran @ 8 Mar 2012 01:39 PM
There is an O(k) solution. An awesome problem!!!

hi admin... i m unable to

rahul1951991 @ 15 Mar 2012 01:00 PM
hi admin... i m unable to understand why the code is giving wrong answer for some cases. pls have a look at code at http://www.codechef.com/viewsolution/915000 nd suggest me what m doing wrong.....!!!

can any buddy please make me

avinash_jain @ 23 Mar 2012 12:58 PM
can any buddy please make me understand the logic behind this problem. How people are calculating the number of particles in any chamber just by taking mod ??

@avnish_jain: until this time

jigsaw004 @ 12 May 2012 08:16 PM
@avnish_jain: until this time you should have figured out the solution..if not..then consider this...the count of each chamber goes from 0 to 0 once (n+1) particles get bombarded in it..for the first chamber, incoming number of particles: a, which can be written as a=q*(n+1)+(a%(n+1)). for the q packets containing n+1 particles each, the count in the 1st chamber remains 0. Therefore, finally a%(n+1) particles reside in the 1st chamber. For, the second chamber, 1st chamber is the source: Let b number of particles comes from 1st chamber to 2nd, then you should have b%(n+1) particles in 2nd chamber by same logic. Express b in terms of a.

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold

HELP

Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:

 

  • Accepted Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark.
  • Time Limit Exceeded Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.
  • Wrong Answer Your program compiled and ran succesfully but the output did not match the expected output.
  • Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.
  • Compilation Error Your code was unable to compile. When you see this icon, click on it for more information.
  • If you are still having problems, see a sample solution here.

CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com