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
    • May Cook-Off 2013
    • May Challenge 2013
    • April Cook-Off 2013
    • April Challenge 2013
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • Campus Chapters
    • Host your Contest
    • Go for Gold
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
    • Top Contributors on Discuss
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Practice(Peer) » Odd

Odd

Problem code: DCE05

  • Submit
  • All Submissions

All submissions for this problem are available.

The captain of the ship TITANIC is a little .... off the track. He needs to select the crew for the ship. But everyone seems to be eligible. So to test their intelligence, he plays a game.
The contestants have to stand in a line. They are given the numbers in the order in which they stand, starting from 1. The captain then removes all the contestants that are standing at an odd position.
Initially, standing people have numbers - 1,2,3,4,5...
After first pass, people left are - 2,4,...
After second pass - 4,....
And so on.
You want to board the ship as a crew member. Given the total number of applicants for a position, find the best place to stand in the line so that you are selected.

Input

First line contains the number of test cases t (t<=10^5). The next t lines contain integer n, the number of applicants for that case. (n<=10^9)

Output

Display t lines, each containg a single integer, the place where you would stand to win a place at TITANIC.

Example

Input:
2
5
12


Output:
4
8


Author: uploader0
Date Added: 14-10-2009
Time Limit: 2 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, FORT, FS, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, 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.

main() should return

harry_fgiet @ 21 Nov 2009 03:42 AM

main() should return something.....

Does the time limit holds

apt2D @ 27 Nov 2009 06:40 AM

Does the time limit holds good for Java also?

See the FAQ.

triplem @ 27 Nov 2009 08:18 AM

See the FAQ.

According to me  you cannot

luckyzoner @ 17 Dec 2009 11:06 AM

According to me  you cannot do static memory allocation during runtime..As you are doing long int num[n]...Instead u should try using pointers and then allocate desired memory for inputs to be taken. 

Look up what %i means.

triplem @ 20 Dec 2009 03:44 AM

Look up what %i means.

Needed to know the general

alok @ 20 Dec 2009 07:54 AM

Needed to know the general output format.

Should it be :

1. test cases:

Input

Output

....

OR

2.

Test cases:

All inputs

All outputs

 

I am asking this cause in some solutions given on Codechef followed both formats and accepted. When I put something, it's giving TLE.

You aren't printing the input

triplem @ 20 Dec 2009 08:04 AM

You aren't printing the input back to the screen, only the output, and it makes absolutely no difference at what time during your program's execution you do this, as long as the output is correct.

Your code doesn't actually work properly on the sample input; have you not tested your program at all?

Okay, I looked up what "%i"

Flopsy @ 21 Dec 2009 08:19 AM

Okay, I looked up what "%i" means, made the appropriate change and got "Correct". Thanks.

Is n >=2 ? If not then what

TrialAndError @ 25 Dec 2009 02:01 AM

Is n >=2 ? If not then what should happen when n = 1.  n means the number of applicants.

With only one person it

triplem @ 25 Dec 2009 03:05 AM

With only one person it should be pretty obvious at what point they should stand..

Yea its obvious.

TrialAndError @ 25 Dec 2009 03:36 AM

Yea its obvious. But theoretically,  1 is odd. And the specification says that odd number be thrown out.

Anyways, solved it.

Well, in that case, there's

triplem @ 25 Dec 2009 08:43 AM

Well, in that case, there's nothing different between 1 and anything else; you always get down to 1 person eventually, and 1 is always odd. It is implied the game stops when there is 1 person left.

My python code is running

nvteja @ 9 Jan 2010 02:57 AM

My python code is running fine on my system. But when i submit it is giving me runtime NZEC error. Can anyon explain me what it is ?

i get answer in this form for

chirayu @ 15 Jan 2010 08:57 PM

i get answer in this form for 10^9:-

5.368709e+08

Is this ok?

what is time limit and how

chirayu @ 15 Jan 2010 10:53 PM

what is time limit and how it  is calculated?

Hi admin I am submitting

jvip21 @ 27 Jan 2010 06:04 PM

Hi admin

I am submitting solution for this problem, but everytime it says time exceeded.

I would request you to have a look at my logic which is of single line, and give me some direction so as where am going wrong. I dont want to use any unnecessary loops for this problem which am doing but still am getting time exceeded.

Please help.

Thanks

 

 

 

To admins: Probably your test

u2001137 @ 28 Jan 2010 12:59 PM

To admins:

Probably your test cases don't cover a subtle corner case. I have submitted two different solutions to this problem (174407 and 174408). The two solutions differ by only one character. However, with n=8, they produce different answers. Your system has AC both of them. Ideally,174407  shouldn't be AC, it should be WA.

 

It obviously isn't possible

triplem @ 28 Jan 2010 01:54 PM

It obviously isn't possible to cover every single test case. No matter what the test cases are you will be able to write a wrong program that can get accepted; there is no need to change the test cases every single time this happens. If your program is right, it will be accepted; that is all that matters.

I have the correct code but

lokeshchandra @ 22 Feb 2010 10:33 PM

I have the correct code but the time limit is exceeded...............

 

No; if you have time limit

triplem @ 23 Feb 2010 01:58 AM

No; if you have time limit exceeded, then you do not have the correct code.

@viswateja nelakuditi: I have

linkid @ 16 Mar 2010 12:26 PM

@viswateja nelakuditi:

I have the same problem (runtime error) but I don't understand why. If somone car check my code which is simple (http://www.codechef.com/viewsolution/211516).

Thanks.

please somebody reply

mayank2108.singhania @ 4 Apr 2010 12:35 AM

please somebody reply

@Mayank: Using iostream is

jarnbjo @ 7 Apr 2010 05:32 AM

@Mayank: Using iostream is far too slow.

@mayank at max your number of

anubhav.iiitm @ 15 Apr 2010 05:11 PM

@mayank at max your number of iterations can b:

10^6*10^9+10^6 which is very very large figure...

i have written the

mygaurav @ 16 Apr 2010 10:21 PM

i have written the code

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

1 can output be given as input is given(Method 1) or else how to store results for such a large no of test cases

2 the code written as per Method 1 is giving an internal error??

@gaurav ... read the FAQ.

f03nix @ 16 Apr 2010 11:38 PM

@gaurav ... read the FAQ. Don't include conio.h, its a windows/DOS specific header file.

i submitted the code but it

mygaurav @ 17 Apr 2010 06:24 PM

i submitted the code but it is giving runtime error, plz help:

 

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

You clearly still haven't

triplem @ 18 Apr 2010 02:52 AM

You clearly still haven't read the FAQ.

Read the problem statement.

triplem @ 18 Apr 2010 03:51 PM

Read the problem statement.

you are not printing the

mcsharma1990 @ 18 Apr 2010 03:52 PM

you are not printing the answer in correct format.

it must be printf("%dn", ans[i]) instead of printf("%dn", ans[i]);

ohh this comment section does

mcsharma1990 @ 18 Apr 2010 03:53 PM

ohh this comment section does not show the backslash sign..

@manjot..here again your

mcsharma1990 @ 18 Apr 2010 03:56 PM

@manjot..here again your array SIZE is too small to work for a file with test cases t=10^6

@Tor-Einar Jarnbjo - 7th

ace33 @ 14 May 2010 03:04 AM
@Tor-Einar Jarnbjo - 7th Apr,2010 05:32:23.

@Mayank: Using iostream is far too slow.

 

Not specifically for this problem but I have also had an issue with my programs timing out. What would you use instead of iostream? printf and scanf? or is there a more streamlined way of I/O

I am writing it using Arrays

max_steel @ 18 May 2010 07:58 PM

I am writing it using Arrays in Java.

 

But to store 1 billion of no I need around 4 GB of RAM. That is why I think it is giving runtime error.

 

Anyone used any other data structure?

@ishan no need of any data

devendra088 @ 18 May 2010 11:18 PM

@ishan

no need of any data structure

 

try something diff to solve this

Hey everyone, This is my

sends2aaron @ 21 May 2010 05:54 AM

Hey everyone,

This is my first time posting in one of the CodeChef forums even though I signed up over five months ago. Just a few moments ago I successfully submitted a solution to DCE05, an Easy level problem. The time limit according to the problem statement was 1s.

According to this site, my solution took 5.96s but still passed somehow. How can that be? Don't blast me too hard, Steve. I'm not as advanced at this as you are (yet). :-)

I have a link to my solution that I would like to post, but I am not sure whether or not that is against the rules.

 

~Aaron

That little line saying 'Have

triplem @ 21 May 2010 06:40 AM

That little line saying 'Have you browsed through the FAQ?' right under 'Post new comment' is there for a reason ;)

Oh, yeah. Fine print... :)

sends2aaron @ 21 May 2010 08:41 AM

Oh, yeah. Fine print... :)

"Codechef might test your

sends2aaron @ 21 May 2010 08:42 AM

"Codechef might test your code multiple times with different input files. If your code gives the correct answer within the time limit for each input file, the execution time displayed is the total of the time spent for each test case."

I guess that would be the answer!

somebody please help!

javadecoder @ 21 May 2010 02:57 PM

somebody please help!

you have about 10^6 test

f03nix @ 13 Jun 2010 08:12 PM

you have about 10^6 test cases in that one ... printing the results out through System.out.println individually is probably whats slowing you down.

@abcd: u read to need faq u

AnoopNarang @ 13 Jun 2010 08:55 PM

@abcd: u read to need faq

u dont need to store all inputs and process then print all the output.

just take 1 input process it and print it.... better read FAQ.

need to read** lol

AnoopNarang @ 13 Jun 2010 08:56 PM

need to read** lol

@Antapreet Singh Thanks,I got

javadecoder @ 14 Jun 2010 11:23 AM

@Antapreet Singh

Thanks,I got AC. :)

Can using cin/cout slow you

akhilhandoo @ 14 Jun 2010 03:54 PM

Can using cin/cout slow you down too ?

@akhil- yes it do.. go fa

grv @ 15 Jun 2010 07:15 AM

@akhil- yes it do.. go fa scanf/printf

Please don't post code here

f03nix @ 23 Jun 2010 11:05 PM

Please don't post code here (FAQ), and make sure you go through all the comments before you post a new one. Using System.Out.println is probably whats slowing you down.

ADMIN here is my

sanchit.mittal @ 26 Jun 2010 08:29 PM

ADMIN

here is my code

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

plz tell me how can i reduce memory usage,,,

i m getting run time error..:(

@admin... i hav gone through

sanchit.mittal @ 26 Jun 2010 08:43 PM

@admin...

i hav gone through the faq...n i understood..but i m not getting how to avoid the use of large arrays or make dem fit in memory

is dis bcoz m declaring large

sanchit.mittal @ 26 Jun 2010 08:47 PM

is dis bcoz m declaring large array like a[1000000] inside a function....

admin plz reply.....

http://www.codechef.com/views

sanchit.mittal @ 26 Jun 2010 09:09 PM

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

wats the problem now its using 9.3 m of memory....i hav declared array outside functions.....plz help admin

ADMIN: Well, the

shrutiranjans @ 30 Jun 2010 11:03 PM

ADMIN:

Well, the straightforward code got accepted for me. But when I am going for faster I/O processing, I am getting a wrong answer. I do not know where I am going wrong, as my answers seem to be correct for the test cases.

Link to my code is:

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

@admin I have solve this

pandey_adarsh @ 2 Jul 2010 03:47 AM

@admin

I have solve this problem in java, algorithm executed for 10^6 values take system mili time

Start: 1278022137699
End: 1278022137717

 

But, when execute on the your enviorment it always says time limit exceeds.

Can you tell me is there are some problem in I/O.

Your code doesn't appear to

triplem @ 13 Jul 2010 03:09 PM

Your code doesn't appear to be related to this problem in the slightest. What problem are you trying to solve?

@ sanchit 1 obvous mistake

mcsharma1990 @ 13 Jul 2010 04:58 PM

@ sanchit 1 obvous mistake in your code that i have found us that while you are outputting the data.

using printf("%ldn",&b[i]) you should use b[i] and NOT &b[i]

 

Also your algo is o(n) which will certainly get TLE.


@Stephen can u plz check for

Juned123 @ 13 Jul 2010 05:07 PM

@Stephen

can u plz check for which testcase my program is giving wrong answer.

My submission id is 287951.

somebody please reply

gomsi_ @ 9 Aug 2010 10:15 PM

somebody please reply

try pow((double)2,j-1)

Oleg @ 10 Aug 2010 12:12 AM

try pow((double)2,j-1)

the main thing is... the

gomsi_ @ 10 Aug 2010 06:31 PM

the main thing is...

the function pow always return a double, so to make it integer, I used typecasting and used long to have the required range of int.

how would this ( pow((double)2,j-1)) help??

suggest something else

thanks

 the main thing is...the

gomsi_ @ 10 Aug 2010 06:35 PM

 the main thing is...

the function pow always return a double, so to make it integer, I used typecasting and used long to have the required range of int.

how would this ( pow((double)2,j-1)) help??

suggest something else

thanks

somebody please reply

gomsi_ @ 11 Aug 2010 08:26 AM

somebody please reply

@pruthvi: l=2**times what

gomsi_ @ 12 Aug 2010 10:17 PM

@pruthvi:

l=2**times

what does this statement do??

Can somebody please post some

ronzii @ 22 Aug 2010 12:02 PM

Can somebody please post some testcases??

Hi Admin, I solved this in

webspiral @ 1 Sep 2010 11:56 AM

Hi Admin,

I solved this in PHP with the mose optimised algorithm. Still i get time limit exceeded. Can you please point me where i am doing wrong. This is my solution.

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

Hey Shuaib, I noticed that

SixtyBy3 @ 2 Sep 2010 01:03 AM

Hey Shuaib, I noticed that you are using BigIntegers in your solution, when int by itself is perfectly capable of handling the data the will be encountered while solving the problem. BigInteger will only slow down the execution and lead to TLEs. Use primitives.

Tell me something...in the

webspiral @ 2 Sep 2010 01:17 AM

Tell me something...in the input, we are passing a text file which contains the test cases right ? || Are we passing the numbers directly and getting the output ?

For those of you who are

SixtyBy3 @ 2 Sep 2010 01:35 AM

For those of you who are trying to solve this using Java, you can try using a StringBuffer to store your results instead of an array of integers (which seems to be the conventional approach). With this method, you will prevent memory leaks that might occur when you try this with an array. Plus the StringBuffer objects are built thread-safe, if you are trying that sort of thing.

I got an execution time of 2.47 seconds with my solution. Not sure how many test cases were involved but I tried at home with the maximum specified of one million and noticed that the only bottleneck was the speed with which the display could print one million strings.

So, give this a try. Hope it all works out for you.

@Mayank, Where in the problem

tijoforyou @ 15 Sep 2010 05:05 PM

@Mayank,

Where in the problem statement does it tell you to print out unnecessary information?

pheeeew, Passed !!!

webspiral @ 18 Sep 2010 01:10 PM

pheeeew, Passed !!!

i am fed up of this time

amangarg67 @ 29 Sep 2010 01:23 AM

i am fed up of this time delay error suggest something please

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

Hi Sir I submitted  my code.

yelyenyes @ 8 Oct 2010 01:55 PM

Hi Sir I submitted  my code. It was accepted but shows 0M memory and 0s execution seconds why????

Please don't post code here;

triplem @ 13 Oct 2010 06:02 AM

Please don't post code here; read the FAQ.

As the FAQ says, any main method must always return 0; not returning 0 is the definition of runtime error.

@Stephen, I changed the

sankalan @ 14 Oct 2010 08:08 AM

@Stephen,

I changed the return statement from 1 to 0,

but still geting the same runtime error (SIGSEV)

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

check the solution here

thanks

I hadn't read the rest of

triplem @ 14 Oct 2010 10:39 AM

I hadn't read the rest of your code yet, but you still haven't read the FAQ. You aren't allowed to read from files.

Read the FAQ. You have lots

triplem @ 22 Oct 2010 03:52 AM

Read the FAQ. You have lots of mistakes in your code.

Hey guys, so i am using scanf

abotsch31 @ 3 Nov 2010 03:10 PM

Hey guys, so i am using scanf to get my input but when i my output just adds onto my input when i output it with printf. How do i get it where the output is by itself instead of after the input.

PS: I tried System('CLS'); but it gave me an error.

As I mentioned in the comment

triplem @ 3 Nov 2010 03:34 PM

As I mentioned in the comment right above yours, read the FAQ.. it tells you exactly that.

As is explained in the FAQ

triplem @ 4 Nov 2010 01:57 AM

As is explained in the FAQ which you clearly still haven't read, only your output is important. The judge tests your program by redirecting the standard input stream to a file, and then compares that file with the expected file. It makes no difference whatsoever at what point in your program you read input, since the judge can never tell.

That solution will give a runtime error since you are told there could be a million test cases but your array is only of size 1000.

Andrew, using an array with 1

jedicoder @ 5 Nov 2010 11:38 AM

Andrew, using an array with 1 million should be fine on gcc 4.008.  Using anything less will yield the wrong answer.

here number of applicantants

amogha @ 30 Nov 2010 08:57 PM

here number of applicantants can be 10^9. However many solutions have used int to read it however int size being 2 bytes or 4 bytes can read maximum number of 2*10^6. However all solutions have been judged right including mine. Why would it be so.

The maximum value that can

triplem @ 1 Dec 2010 01:38 AM

The maximum value that can fit in an int on virtually all compilers these days is 2^31 - 1 = 2147483647 > 10^9.

The exact same logic is

skasturi @ 2 Dec 2010 09:10 PM

The exact same logic is ACCEPTED when written  in C++ but times out in Java!

Java: http://www.codechef.com/viewsolution/388087

C++: http://www.codechef.com/viewsolution/388052

Am I missing something?!!!

 

It says it took 1.35 s to

ingridmorstrad @ 15 Jan 2011 03:00 AM

It says it took 1.35 s to compile my program. Time limit is one second. Yet, successful.

Mistake?

Yes. The mistake being that

triplem @ 15 Jan 2011 04:06 AM

Yes. The mistake being that you didn't read the FAQ :P

It's funny how that's the

ingridmorstrad @ 15 Jan 2011 02:30 PM

It's funny how that's the answer to most questions. Thanks :)

o my god mene ye saite join

ishupre @ 15 Jan 2011 03:09 PM

o my god mene ye saite join kar ke galti kar de mujhe to problm he samj nhi aye :( m just 12 pass na and doing btech in 1st year nw

just now submitted the ans

zero_cool @ 19 Jan 2011 01:20 AM

just now submitted the ans twice got timed out once and correct second .I only changed the c++ io to C io i am amazed at how much difference this makes

@admin i cooked the code and

tj91 @ 22 Jan 2011 11:08 PM

@admin i cooked the code and it works gr8

but time imit exceeded.

For 1000000000 the answer i got in my  pc in 4 seconds

the ans was 536870912 pleez tell me whether its correct or not

although i coudnt submit but m happy that i framed the code:)))

what does SIGSEGV error

chinmay92m @ 26 Jan 2011 11:58 AM

what does SIGSEGV error mean???

FAQ

triplem @ 26 Jan 2011 12:21 PM

FAQ

@ all Java programmers.. as

pkamath @ 27 Jan 2011 10:00 AM

@ all Java programmers..

as mentioned in most of the above posts, most of us hit the "timing exceeded" problem because of sysout after processing each input (like in the previous problems). store and bulk output as a single string.

@stephen please tell the

tj91 @ 28 Jan 2011 01:26 AM

@stephen please tell the answer for 1000000000

i got the ans in 4 secnds in my pc

it was 536870912

Read the 'Input' section.

triplem @ 6 Feb 2011 12:50 AM

Read the 'Input' section. (And also the FAQ).

Hi admin how is it possible

kartikanand92 @ 9 Feb 2011 12:42 AM

Hi admin

how is it possible that both yelyenyes (submission no. 353156 ) and expo (submission no. 354225) have successful submissions when both of them produce different ouputs for the same input

For eg.

yelyenyes's output or test cases

1 is 0

2 is 1

4 is 2

and expo's output is

1 is 1

2 is 2

4 is 4

clearly expo's ouptut is correct !!!

even i am getting wrong answer for the same ouputs!!!

Runtime error means your main

triplem @ 10 Feb 2011 01:36 AM

Runtime error means your main function is not returning 0. Your main function will never return 0.

I had attempted this problem

ark202 @ 11 Feb 2011 05:33 PM

I had attempted this problem 7 times out of which 1 had a compilation error and the rest exceeded time limit.

I'm quite confused here as the version ID454541 is the exact copy of a successful submission by gowri sundaram and still fails on the time limit.

Versions ID454120 & ID454330 has a complexity of n2

I had later submitted a modified solution in versions ID454523 & ID454536 such that the complexity is n and suprisingly it still fails on the time limit.

Please clarify.

I have tried submitting my

shahensha @ 11 Feb 2011 09:15 PM

I have tried submitting my solution many times. But still it times out. Here is my solution#mce_temp_url#!

Please have a look at it and help me. I am stuck!

please reply admins!

shahensha @ 11 Feb 2011 11:32 PM

please reply admins!

Same problem...no mater what

gravity @ 13 Feb 2011 07:21 PM

Same problem...no mater what i try....it times out!!!!....help please...

df

gauravalgo @ 13 Feb 2011 08:49 PM

df

is there any one out

shahensha @ 13 Feb 2011 10:55 PM

is there any one out there...??????

i can hear you...!!!!

rafaftahsin @ 14 Feb 2011 07:41 AM

i can hear you...!!!!

Then please help me out!

shahensha @ 16 Feb 2011 10:28 PM

Then please help me out!

Your operations such as log

mkagenius @ 21 Feb 2011 05:59 PM

Your operations such as log and pow are time consuming i guess.

Whatever code i write it is

sonoftheearth @ 22 Feb 2011 07:43 AM

Whatever code i write it is giving me tle....... why so????? i even tried pasting some code which the site indicated was solved in 0.0s...... I have been finding this problem for all questions... Can Someone explain y????

i think there is some thing

hansfryko @ 6 Mar 2011 11:54 PM

i think there is some thing wrong with this exercise

 

i mean,

 

if the contestn is 4,

so it will be

 

1234

24

4

so the answer is 4

but i try code that wriiten by the 'correct' solver, it will result 2, not 4.

hows your opinion?

hansfry..you are

fluteofcoder @ 11 Mar 2011 04:38 PM

hansfry..you are right..rather than caring about other code ..make your own

then only you ll be known as codechef

Please explain the three

cvam @ 14 Mar 2011 11:20 AM

Please explain the three lines in Input. For this problem We need 3 data :

1) no. of vacancies,

2)no. of applicants

3) no. of times the captain removes people(i.e. passes)

In Problem explanation Under Input heading a woed 'test case' is specified. What is test case here ? Is it no. of Passes? And explanation says 'next t lines are no. of applicants for case'. Do we need to solve this problem for t (no. entered in first line) cases ?

Then We have no. of applicants for each cases but What is no. of vacancies (or members in a crew)  and how many passes for each cases. where is two data for each cases. Any one please explain me

 

 

i have undestood the problem

shaileskishore @ 17 Mar 2011 08:59 PM

i have undestood the problem ....

can smbody give me the logic to solve this

@shailesh kishore If you have

default1130 @ 17 Mar 2011 09:15 PM

@shailesh kishore

If you have understood the problem then try to find out the answer for more number of test cases and see the pattern of the output.

the class name is Main and

Priteesh ranjan @ 17 Mar 2011 11:39 PM

the class name is Main and not  ODD

I never knew that scanf and

prabhatcraz @ 24 Mar 2011 01:31 PM

I never knew that scanf and cin would result me a difference in submission....

It seems that the codechef

walson_dias @ 29 Mar 2011 11:39 AM

It seems that the codechef tester is down... it gives time limit exceeded. I had a look the sample codes that have successfully executed.. Mine should certainly work faster than theirs... SOMEONE PLZ look into this

This problem tester is not

walson_dias @ 1 Apr 2011 11:44 AM

This problem tester is not working for JAVA. ...It always says Time limit exceeded.... Even for the code which shows successful submission above... What a joke.!!!

WHAT IS THE OUTPUT FOR INPUT

clmathuriya @ 3 Apr 2011 08:06 PM

WHAT IS THE OUTPUT FOR INPUT =2      ?????????????

DATA IS INCOMPLETE

amitgodre @ 10 Apr 2011 06:58 PM

DATA IS INCOMPLETE

Something is seriosly wrong

imdeepakg @ 12 Apr 2011 02:06 PM

Something is seriosly wrong with the way codechef judge deals with languages. I was getting TLE for my JAVA program but exactly same Algo passed for C programm.

I have felt it for some other problems also. Is using Java for such programming contests is not a Good Idea!

sir please reply to problem

sid448 @ 20 Apr 2011 10:51 PM

sir please reply to problem

i am gettin a runtime

nikgpuec @ 23 Apr 2011 06:42 PM

i am gettin a runtime error.plz help me out.

somthing wrong with you i

aadish26 @ 26 Apr 2011 09:26 PM

somthing wrong with you i have even submitted a copy of accepted program it still says tim limit exceeded..

Yes even I did same...

sultanahamer @ 3 May 2011 10:10 AM

Yes even I did same... Submitted accepted program and is saying time limit exceeded....

Why am I getting runtime

kapilagarwal @ 12 May 2011 08:14 AM

Why am I getting runtime error SIGABRT ? I have read FAQ but donot understand why it gives this error even when I'm using long when there are solutions which are using only int ?

I Don't lIke tHis ideA Of A

bodmas @ 23 May 2011 07:14 PM
I Don't lIke tHis ideA Of A laNgUagE beinG givEN an uPpER HanD THan anoThEr. i've seVERallY SubmitteD a WElL-opTiMiZed JaVa cOde wHicH iS fAsTer thAN some SubMitted solutiOns ANd yEt am gettIng a TLE. ADMin PlS loOk intO IT.

hey my code is dis!! But here

shivalijindal @ 28 May 2011 10:10 AM
hey my code is dis!! But here it says "WRONG ANSWER" can anyone tell me wat's wrong...i m not able to identify the mistake uptil now! :( #include int main() { long int t, i; long int n, j=1; scanf("%ld",&t); for(i = 0; i

#include int main() { long

shivalijindal @ 28 May 2011 10:52 AM
#include int main() { long int t, i; long int n, j=1; scanf("%ld",&t); for(i = 0; i

This does not make sense. I

sujeet97 @ 30 May 2011 10:53 PM
This does not make sense. I have uploaded a code that is even more optimized than the accepted once and also tried uploading the accepted ones itself. But it shows "exceeded the time limit". Has the time limit got to do anything with my connection speed. I am forced to think this way because I can't find a better explanation.

Yeah this needs to be marked

eipie @ 31 May 2011 09:36 PM
Yeah this needs to be marked correct for me / Codechef needs to upgrade the time limit on this. This is stupid.

I agree ... The problem seems

mustardbrain @ 1 Jun 2011 12:37 AM
I agree ... The problem seems to be with Java codes only. The last accepted Java solution ran for some 8 seconds ...

I am getting "Time Limit

hugohabel @ 5 Jun 2011 10:47 PM
I am getting "Time Limit Exceeded" error. I started with PHP, then optimized my code a lot, still getting the same error. Translated the same code to C and still getting the same error. I don't understand.

what d hell is going on.....

umal_20 @ 13 Jun 2011 03:24 PM
what d hell is going on.....

hi Admin, i am not getting

arunkumar1985 @ 14 Jun 2011 02:31 PM
hi Admin, i am not getting where my code is going wrong.Can you please look at it id . 573951 Thanks

Hi all, I solved it in

praveen_av @ 16 Jun 2011 12:32 PM
Hi all, I solved it in JAVA... before getting it right I had tried many times but failed... thats because i was not using faster classes for reading and writing! for reading input use - BufferedReader for writing output use - PrintWriter (dont forget to close the streams before you terminate your program)

hey...i submitted the code of

hungrycoder @ 16 Jun 2011 06:24 PM
hey...i submitted the code of Odd in C...it was workin fine in my compiler..but in codechef it is showing runtime error..i viewed a similar code (successful) in C which gave the same output as that of mine in some 10 or 11 test cases ..can anybody say what is the problem with ma code? #include int main() { unsigned long int a,b,c,i,j,result; scanf("%ld",&a); for(j=0;j

sorry total code dint get

hungrycoder @ 16 Jun 2011 06:29 PM
sorry total code dint get pasted #include int main() { unsigned long int a,b,c,i,j,result; scanf("%ld",&a); for(j=0;j

why my code is not getting

hungrycoder @ 16 Jun 2011 06:30 PM
why my code is not getting posted?

@hungrycoder: Post a link to

balajiganapath @ 16 Jun 2011 06:33 PM
@hungrycoder: Post a link to your code instead of pasting the code itself.

here is the link

hungrycoder @ 16 Jun 2011 06:34 PM
here is the link http://www.codechef.com/viewsolution/575304

@hungrycoder The runtime

balajiganapath @ 16 Jun 2011 06:49 PM
@hungrycoder The runtime error code shown is NZEC which stands for "Non Zero Exit Code". Your program should return 0 at the end. So, just add a "return 0;" statement as the last line in main function. Are you sure your logic is correct? Test your program for corner cases.

@balajiganapath thanks for

hungrycoder @ 16 Jun 2011 07:01 PM
@balajiganapath thanks for the help..i rectified the NZEC and my code got accepted..thank u

http://www.codechef.com/views

benassi @ 21 Jun 2011 03:34 PM
http://www.codechef.com/viewsolution/581057 where is problem..it work fine..:/

this is d

ank007 @ 22 Jun 2011 06:25 PM
this is d link http://www.codechef.com/viewsolution/581653

@ank007 don't use

balajiganapath @ 22 Jun 2011 07:01 PM
@ank007 don't use doubles.....use long

http://www.codechef.com/views

benassi @ 25 Jun 2011 01:17 PM
http://www.codechef.com/viewsolution/581057 :/

I submitted this solution and

evanescent @ 26 Jun 2011 01:44 AM
I submitted this solution and got TLE(which I believe to be efficient since it just uses bitwise operators): http://www.codechef.com/viewsolution/583454 As it did not work even when I tried to resubmit the same solution I tried to submit someone else's solution which was successful and that too gives TLE: http://www.codechef.com/viewsolution/583456 Is this kind of behaviour expected?

It helps to use buffer in

evanescent @ 26 Jun 2011 12:32 PM
It helps to use buffer in output as well .TLE resolved :-).

@balajiganapath hey thnx for

ank007 @ 26 Jun 2011 01:10 PM
@balajiganapath hey thnx for replying but it doesnt work by converting it into long Here is d link http://www.codechef.com/viewsolution/583646

@ank007:u cud learn from my

evanescent @ 27 Jun 2011 12:00 AM
@ank007:u cud learn from my mistake above...2 points...u can use int and that should be gud...and more important dont use system.out.println..use buffered output...u can see http://www.codechef.com/viewsolution/583618

hey tell me ,in the example

shirish47 @ 29 Jun 2011 12:08 PM
hey tell me ,in the example three inputs are shown ,while description says two(t,n) what are those there input.

does ur example say 12

shirish47 @ 29 Jun 2011 12:19 PM
does ur example say 12 candidates 2 test, if its so I don't get this 1,2,3,4,5,6,7,8,9,10,11,12 after 1 pass 2,4,6,8,10,12 after 2 pass 4,8,12 but ur output suggest a wrong answer 4,8 what about 12th candidate????...

simple math technique will

kevinfrankly @ 7 Jul 2011 11:19 PM
simple math technique will solve this problem .. only need 17 lines

can array not have a size of

garima3292 @ 5 Aug 2011 07:37 PM
can array not have a size of 10^9 ? i was trying to do this problem using array !

@admin plzzz tell me the

hg51290 @ 9 Aug 2011 03:38 PM
@admin plzzz tell me the cases where my code fails...

i have chckd for all

shishir0995 @ 15 Aug 2011 04:54 AM
i have chckd for all values and there is no mistake width output pattern

Hello! I have a runtime error

boki @ 20 Aug 2011 05:30 PM
Hello! I have a runtime error right at 0.0 second :( The code works well with ocaml 3.12, have you got any idea about that ? http://www.codechef.com/viewsolution/629422 thank you!

is it d highest power of 2?

dishadp @ 21 Aug 2011 06:54 PM
is it d highest power of 2?

Guys,The Problem essentially

sude2p @ 30 Sep 2011 10:58 PM
Guys,The Problem essentially is Finding the largest 2-power number which is less than n suppose its 69 we have to return 64. 65 is essentially 64+4+1.Therefore turningoff the bits which are at position 4 and 1 will do. doing x=x&x-1 in each step till it becomes 2-power number will do.

Guys,The Problem essentially

sude2p @ 30 Sep 2011 10:59 PM
Guys,The Problem essentially is Finding the largest 2-power number which is less than n suppose its 69 we have to return 64. 65 is essentially 64+4+1.Therefore turningoff the bits which are at position 4 and 1 will do. doing x=x&x-1 in each step till it becomes 2-power number will do.

Respected Admin, I have

aamandeep @ 22 Oct 2011 04:12 PM
Respected Admin, I have submitted my code many times but it shows time exceed. Can you plz check my code where i am wrong. Thanks in advance

my logic is to find the

dharmesh28 @ 27 Oct 2011 05:29 PM
my logic is to find the maximum poower of 2 less than or equal to the number..it is giving TLE?what more should i optimise??

I am getting runtime error

ni8mare @ 8 Nov 2011 01:05 PM
I am getting runtime error for this program. Please help

My solution in C was exactly

somughosh @ 16 Nov 2011 04:59 AM
My solution in C was exactly identical to the one in perl. And I am pretty sure that its the most optimized I could find. Still CodeChef says it crosses time limit... My guess is that it should increase timelimit set for perl programs

@admin, my program works on

lallu1 @ 16 Dec 2011 04:02 AM
@admin, my program works on sourceliar(online ide), there should be no chance of error, please help me to know why it is giving runtime error. My submission is http://www.codechef.com/viewsolution/758039

hey admin,my prog. is giving

spartacus123 @ 16 Dec 2011 07:07 AM
hey admin,my prog. is giving all outputs right as i had it confirmed with many other codes.Can you pleasse tell me why is it giving wrong answer all the time.my submission is http://www.codechef.com/viewsolution/758107

why am i getting "Time Limit

ninja13 @ 20 Dec 2011 09:31 PM
why am i getting "Time Limit Exceeded" ? http://www.codeshef.com/viewsolutions/766379

Please see my code?? which

ssiddharth1989 @ 3 Jan 2012 03:16 PM
Please see my code?? which cases arent covered?? Wht for n=1 ? http://www.codechef.com/viewsolution/777370

Please... Why am i getting

pre1a9_3 @ 4 Jan 2012 09:28 PM
Please... Why am i getting the wrong answer?? Is there any mistake in my logic?? http://www.codechef.com/viewsolution/779469

Protip: There is a solution

geist8 @ 12 Jan 2012 02:04 AM
Protip: There is a solution to this problem in JAVA. You just have to find the appropriate algorithm to handle finding the "Safe Zone". ;-D (Also use PrintWriter, not System.out.println)

@geist8 Thanks for mentioning

angelotan @ 15 Jan 2012 07:08 PM
@geist8 Thanks for mentioning PrintWriter! My previous solution that uses System.out got accepted.

@admin::I think test case

Gajanan.pete @ 24 Jan 2012 04:32 PM
@admin::I think test case where a=2^i is missing in test set. My solutions 807796 and 807807 are both correct. 807796 has while loop like while(pow1[less than]a) and 807807 has while loop like while(pow1[less than or equal to]a) , so both gives different solutions for above mentioned case. Then how come both be correct???

need help in optimizing the

lefirenet @ 4 Feb 2012 07:50 PM
need help in optimizing the speed of this thing... http://www.codechef.com/viewsolution/828742

used PrintWriter, still

lefirenet @ 4 Feb 2012 07:57 PM
used PrintWriter, still considered slow... http://www.codechef.com/viewsolution/828764

finally got it correct... new

lefirenet @ 4 Feb 2012 08:07 PM
finally got it correct... new java knowledge acquired... scanner is slower than buffered reader...

a=input(); i=0; j=0; while i

pra7eek @ 19 Feb 2012 10:06 PM
a=input(); i=0; j=0; while i

my code runs well on my

anuragdixit11 @ 2 Mar 2012 09:53 PM
my code runs well on my compiler why is it giving a runtime error??

my code is running well on my

anuragdixit11 @ 2 Mar 2012 09:57 PM
my code is running well on my compiler but its giving a runtime error during submission, why??

http://www.codechef.com/views

maynard92 @ 6 Mar 2012 09:42 PM
http://www.codechef.com/viewsolution/894837 can anyone tell me wat all test cases i have missed in this code? thanks

Come on, My program is

ankursaha @ 11 Mar 2012 07:36 PM
Come on, My program is running successfully on GNU latest compiler... how come it is facing RUNTIME errror here!!!!!!!!!!!!!!

I had implemented using

studd @ 13 Mar 2012 12:49 PM
I had implemented using binary search but TLE,fall back to general solution but TLE, decreased one computation and got it right....

Cant we give a formula?

s1s5 @ 16 Mar 2012 12:47 AM
Cant we give a formula? (int)Math.pow(2,(int)(Math.log(n)/Math.log(2))) This gives the position.

2^|_ (log(n)/log(2)) _|

s1s5 @ 16 Mar 2012 03:35 AM
2^|_ (log(n)/log(2)) _|

Can any one tell me why i am

WAQAS SHAHID @ 19 Mar 2012 01:46 AM
Can any one tell me why i am getting time limit exceeded error ??? http://www.codechef.com/viewsolution/922211

IT IS POSSIBLE IN JAVA! I

tylerisop @ 29 Mar 2012 11:48 AM
IT IS POSSIBLE IN JAVA! I finally got a correct submission. There are two things (not pertaining to this problem only) you should consider doing to help w/ time limit exceeded submissions for Java: 1. Use Buffered inputs 2. Use PrintWriter for output. One weird thing about this problem is during one submission is I received a runtime error, but I could not figure out why! However, I submitted it AGAIN and it was correct. So, try submitting again if you get a "weird" error. Also, you cannot brute force this problem without wasting A LOT of time. If you have any questions feel free to ask.

These problems are useless

jhala_vijay @ 1 Apr 2012 07:23 PM
These problems are useless !!! Nobody can solve these problem in PHP. @Admin: Can you please take care of language specific timings. for example C/C++/JAVA can solve in very less time compared to PHP but these problems have the same time for all the languages. Also I didn't found any solution in the PHP. Is it really possible in PHP?

hello admin, my code is

nitinyadav @ 3 Apr 2012 09:04 PM
hello admin, my code is running well on my compiler but it gives a runtime error during submission .. why ??? check my submission here : http://www.codechef.com/viewsolution/950627

I would like you to go

ashu89_shukla @ 16 Apr 2012 09:47 PM
I would like you to go through my last submission. I feel it is giving correct outputs. Let me know please.

where is the problem ...... u

ale_38 @ 14 May 2012 11:00 PM
where is the problem ...... u can see my code.... http://www.codechef.com/viewsolution/1044417

is brute force necessary

saroj @ 20 May 2012 09:12 PM
is brute force necessary ?? cant we use josephus problems fomula ...:-)

same code in c++ gives time

kushdilip @ 20 May 2012 09:23 PM
same code in c++ gives time limit exceed but in c the exactly similar code succeeds .. what's the problem with c++.

too cruel for python :|

s1aurabhpal_7 @ 22 May 2012 01:46 AM
too cruel for python :|

@kushdilip: cin and cout are

betlista @ 22 May 2012 04:25 PM
@kushdilip: cin and cout are too slow, read here - http://www.codechef.com/problems/INTEST

#include main() { int

shil @ 23 May 2012 01:31 AM
#include main() { int x,y,d[100]; printf(" enter the no. of ppl boarding"); scanf("%d", &x); for(i=1; i

@shil read FAQ about NZEC -

betlista @ 23 May 2012 02:55 AM
@shil read FAQ about NZEC - http://www.codechef.com/wiki/faq#Why_do_I_get_an_NZEC

i checked last ,first, mid

evil_prince @ 26 May 2012 12:28 AM
i checked last ,first, mid values.....answers are same through my code and a submitted code......but when i submit it...i get answer "wrong answer" ...........please admin tell me a condition for which my code is wrong....

I am getting this on my

xcode @ 10 Jun 2012 12:48 AM
I am getting this on my compiler "$ g++ t.cpp; time ./a.exe 2 5 12 4 8 real 0m2.215s user 0m0.030s sys 0m0.030s" but here it shows wrong answer. what is the problem is the???

and now its showing time

xcode @ 10 Jun 2012 12:51 AM
and now its showing time limit exceeded for the same solution. wtf??

i think no of vacancies needs

sheldobot @ 11 Jun 2012 08:19 AM
i think no of vacancies needs to be specified

plz help

sheldobot @ 11 Jun 2012 08:19 AM
plz help

The correct formula to solve

kuruma @ 12 Jun 2012 02:12 AM
The correct formula to solve this problem is already stated above by s1s5

#include void read_num(int

omsairam @ 13 Jun 2012 07:10 PM
#include void read_num(int limit) { int x=0; unsigned int a[limit]; while(limit!=0) { a[x++]=limit--; } calculate(a,x); } void calculate(unsigned int a[],int x) { int j=0; unsigned int b[x]; while(x!=0) { if(x%2==0) { b[j++]=a[x]; } x++; } calculate(b[],j); } int main() { int x,limit,y=0; scanf("%d",&x); while(x!=0) { scanf("%d",&limit); read_num(limit); x--; } } i thought of doing the calculate function recursively.....but i dont know how to give the termination to that function and display the answer....anybody pls help....

i dont want to enlist on

rajat123 @ 30 Jun 2012 03:51 PM
i dont want to enlist on titanic :P

my solution is running in my

animesh_1993 @ 4 Jul 2012 11:24 AM
my solution is running in my pc ,but here it is showing runtime error . please help me

Why is this code exceeds time

madhairsilence @ 15 Jul 2012 03:07 PM
Why is this code exceeds time limit. This is in O(n2) like all other codes use strict; use warnings; my $limit = <>; my $i=0; my $range; my $oddList=""; while( $limit > 0){ $range = <>; for( $i= $range; $i>0 ; $i--){ if( ($i & ($i-1)) == 0 ){ $oddList = "$oddList$in"; last; } } $limit--; } print $oddList;

Hep ppl can anybody tell me

tank113 @ 22 Jul 2012 03:41 PM
Hep ppl can anybody tell me what might be the reasons the code is showing run time error though it is running perfectly on system..plz help

My python code gives runtimes

keyjale @ 2 Aug 2012 05:11 PM
My python code gives runtimes error http://www.codechef.com/viewsolution/1209573 While my pretty similar C code gives correct answer http://www.codechef.com/viewsolution/1209419 Have no idea why.

Oh, I solved it. Just

keyjale @ 2 Aug 2012 05:24 PM
Oh, I solved it. Just replaced input() with raw_input(). I guess, using input() is not advised, but I didn't notice any remark about that in the FAQ.

Why this code is not working.

co_aksh @ 23 Aug 2012 07:59 PM
Why this code is not working. http://www.codechef.com/viewsolution/1279818. replacing fastint() and fastout() with printf and scanf got the same code accepted. http://www.codechef.com/viewsolution/1227345.can anyone tell??. its working fine on my gcc as well as mingw compiler.

Admin, My worst-case time

rahullak @ 27 Aug 2012 02:39 PM
Admin, My worst-case time complexity is 30 T, where T is no.of test cases. But even this is rejected with Time Limit Exceeded in Java. :(

WTH! My worst-case complexity

rahullak @ 27 Aug 2012 02:55 PM
WTH! My worst-case complexity is now T! And it's still TLE!

Finally, got it! Printing

rahullak @ 27 Aug 2012 03:00 PM
Finally, got it! Printing output in each iteration is a bad idea. Storing the results and printing them with a single statement seems to work.

I followed the tutorial of

elva136 @ 23 Sep 2012 11:38 AM
I followed the tutorial of odd and used 2^floor(log2(N)) to compute the result and getting runtime error all the time, although I know its ridiculous for the code with a single line to be accepted within 0.02 s while the best code managed a 0.05 (am a beginner but a misguided optimistic :P) , but I really wanna know whats wrong? I am getting the correct result for 10^9 using res=(int)pow(2,floor(log2(n))) but still it is giving me a runtime error? anything wrong with the logic? and using primitive data types only. Admin, please help?!

@elva136, I wrote the

kuruma @ 24 Sep 2012 04:43 AM
@elva136, I wrote the tutorial for Odd... please to output res use a float data type with 0 decimal places instead of int...

okay got accepted using long

elva136 @ 26 Sep 2012 11:58 AM
okay got accepted using long data type with 0.98 s though, in C. thanks admin!

#include #include int kk(int

rajat1293 @ 30 Sep 2012 01:49 AM
#include #include int kk(int p) { int x; x=log(p)/log(2); return (x); } main() {int l,i,n,k; printf("enter the numberof test casesn"); scanf("%d",&n); for (i=1;i<=n;i++) {printf("enter the number of applicants"); scanf("%d",&k); l=kk(k); l=pow(2,l); printf("%dn",l); } } getting runtime error ,help guys

Please tell me wats wrong

swas_99 @ 5 Oct 2012 05:17 PM
Please tell me wats wrong with this solution -- ID = 1407827

Please..help me with the

rudra_101 @ 12 Oct 2012 10:32 PM
Please..help me with the problem of runtime error. Can anyone see my code??

my code's code

rudra_101 @ 12 Oct 2012 10:34 PM
my code's code is1465920..please help me out

TLE everytime in java. This

jindal_bit @ 18 Oct 2012 11:11 PM
TLE everytime in java. This question is impossible to be solved in java. Waste of time for Java programmers

@jindal_bit: I've solved it

dreamlane @ 19 Oct 2012 04:52 AM
@jindal_bit: I've solved it in Java... so it's not impossible.

can i have more test cases??

vignesh07 @ 18 Nov 2012 08:29 PM
can i have more test cases?? i have to verify my logic.. i do submited my answer.. It showed wrong. Please help.

here written that the time

abhi_93104 @ 4 Jan 2013 01:12 AM
here written that the time limit is 2 sec n my code excepted taking 4.05 sec so please recheck the time limit n correct it Thank you

My code isnt getting executed

goutamgm @ 4 Jan 2013 11:12 PM
My code isnt getting executed for inputs like 100 itself. It gets runtim error #include int main() { int t,a,i,j,c,d,test; scanf("%d",&test); int n[test+1],testin[test+1],testout[test+1]; for(t=0;t

I keep on getting TLE for my

kramer @ 8 Jan 2013 03:23 PM
I keep on getting TLE for my Java code. Here is the link:http://www.codechef.com/problems/DCE05. I am using log function from Math library. Do I need to define my own functions?

my code is running perfectly

aashishgoyal @ 9 Jan 2013 01:29 AM
my code is running perfectly on my system...can somebody plz check and let me knw the error in my code http://www.codechef.com/viewsolution/1696954

Can anyone tell why I am

goutamgm @ 16 Jan 2013 12:01 AM
Can anyone tell why I am getting runtime error but getting right answer for all the test cases #include #define SIZE 100000 int main() { int t,a,i,j,c,d; unsigned long n[SIZE],test,testin[SIZE],testout[SIZE]; scanf("%d",&test); for(t=0;t

Can anyone help me out, why I

ram87reddy @ 22 Jan 2013 11:39 PM
Can anyone help me out, why I am getting Wrong Answer, whereas it is showing right values on my machine. Solution link: http://www.codechef.com/viewsolution/1745235

@ram87reddy : I ran your code

vineetpaliwal @ 23 Jan 2013 01:20 AM
@ram87reddy : I ran your code on the sample input given with the problem : 2 5 12 , it produces only 4 as output while the expected output is : 4 8 You are taking a lots of troubles with regard to I/O . And your problem also lies there . If there is no endline character but end of file when the last input is read , you are not recognizing that input . When the file ends the read() function returns null whose ascii value is 0 unlike whose ascii value is greater than digits . To read input you should prefer to use BufferedReader . BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ; Then read a complete line together , it will read it for you irrespective of whether it ends with end of file or newline . String str = br.readLine(); Then use the parseInt() function of Integer class int testCases = Integer.parseInt(str) Though not needed in this example suppose the line contains two numbers which you have to read seperately , then write String str = br.readLine(); int blank = str.indexOf(" "); int one = Integer.parseInt(str.substring(0,blank)); int two = Integer.parseInt(str.substring(blank+1)); In case a single line contains thousands of integers , you should not use the string substring function because it gets inefficient because every time a substring is created the entire of it copied at a newly allocated space . I have written a small snippet which i repeatedly use in contests whenever I have to read many numbers from a single line . Do let me know if you need it . Hope that helps .

@ram87reddy : I meant unlike

vineetpaliwal @ 23 Jan 2013 01:21 AM
@ram87reddy : I meant unlike backslash n ( the newline character ) . Somehow the backslash did not come when i posted my comment

can anyone plz help me wid

jkdihenkar @ 12 Mar 2013 09:06 AM
can anyone plz help me wid this... y wrong answer???

this is my solution :

jkdihenkar @ 12 Mar 2013 09:07 AM
this is my solution : http://www.codechef.com/viewsolution/1935685 it shows wrong ans!!!

Piece of cake.. I did this in

divyenduz @ 7 Apr 2013 08:16 PM
Piece of cake.. I did this in 10 lines.. http://www.codechef.com/viewsolution/2004132 -_-

http://www.codechef.com/statu

bibinpreethy @ 21 Apr 2013 11:48 AM
http://www.codechef.com/status/DCE05,bibinpreethy i got accepted wen i submitted using scanf() but using cin>> its not getting accepted...:( what could be the possible reason?? anyone please help.........

can anyone tell me why this

kcahdog @ 17 May 2013 12:37 PM
can anyone tell me why this python code is showing NZEC? http://www.codechef.com/viewsolution/2165947 I submitted similar code in C++ and C and they were accepted

SUCCESSFUL SUBMISSIONS


Fetching successful submissions

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