You are not logged in. Please login at www.codechef.com to post your questions!

×

Why does this code for Ciel and Recipet fail ?

I have tried this code twice but it gives me wrong answer always.

Can anyone help me to know as to where I go wrong in the code ? I pass easily on the Sample input using gcc 4.8.2. CODE:

#include <stdio.h>

int main(void)
{
    int t;
    scanf ("%d\n", &t);
    while (t--)
    {
        int i = 0, sum = 0, m;
        scanf ("%d\n", &m);
        i = 13;
        while (i-- > 0)
        {
           if (m >= 2048)
           {
               m /=2048;
               sum++;
           }
           if((m & (1 << i)) != 0)
           {
               sum++;
           }
        }
        printf ("%d\n", sum);
     }
return 0;
}

asked 01 Aug '14, 22:18

nibnalin's gravatar image

6★nibnalin
1611516
accept rate: 0%

Thanks in advance :)

(01 Aug '14, 22:18) nibnalin6★

@betlista

Yes the answer is not 3.

@nibnalin : Please re-read the problem statement carefully specifically this part. "Note that if she orders the same menu twice, then it is considered as two menus are ordered."

4096=2048+2048

=> Only 2 menus are ordered.

link

answered 02 Aug '14, 05:31

ironmandhruv's gravatar image

4★ironmandhruv
333239
accept rate: 20%

Are you sure, that for

1 
40960

the answer is 3 ?

link

answered 01 Aug '14, 22:47

betlista's gravatar image

3★betlista ♦♦
16.9k49115225
accept rate: 11%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,470
×538
×4

question asked: 01 Aug '14, 22:18

question was seen: 569 times

last updated: 02 Aug '14, 05:31