304 North Cardinal St.
Dorchester Center, MA 02124

# Ciel and Receipt CodeChef Solution

## Problem – Ciel and Receipt CodeChef Solution

Tomya is a girl. She loves Chef Ciel very much.

Tomya like a positive integer p, and now she wants to get a receipt of Ciel’s restaurant whose total price is exactly p. The current menus of Ciel’s restaurant are shown the following table.

Note that the i-th menu has the price 2i-1 (1 ≤ i ≤ 12).

So please find the minimum number of menus whose total price is exactly p. Note that if she orders the same menu twice, then it is considered as two menus are ordered. (See Explanations for details)

### Input

The first line contains an integer T, the number of test cases. Then T test cases follow. Each test case contains an integer p.

### Output

For each test case, print the minimum number of menus whose total price is exactly p.

### Constraints

1 ≤ T ≤ 5
1 ≤ p ≤ 100000 (105)
There exists combinations of menus whose total price is exactly p.

### Sample 1:

``````Input:
4
10
256
255
4096
Output:
2
1
8
2``````

### Explanation:

In the first sample, examples of the menus whose total price is 10 are the following:
Here the minimum number of menus is 2.

In the last sample, the optimal way is 2048+2048=4096 (2 menus). Note that there is no menu whose price is 4096.

## Ciel and Receipt CodeChef Solution in Pyth 3

``````# cook your dish here
for _ in range(int(input())):
p = int(input())
a = [2048,1024,512,256,128,64,32,16,8,4,2,1]
b=0
while p>0:
for i in a:
if p%i==0:
p -=i
b +=1
break
print(b)``````

## Ciel and Receipt CodeChef Solution in C++14

``````#include <iostream>
using namespace std;

int main() {
int t;
cin>>t;

while(t--)
{
int n;
cin>>n;
int r=0;
int array[12]={1,2,4,8,16,32,64,128,256,512,1024,2048};
for(int i=11;i>=0;i--)
{
if(n>=array[i])
{
r+=(n/array[i]);
n=n%array[i];
}

}
cout<<r+n<<endl;
}
return 0;
}
``````

## Ciel and Receipt CodeChef Solution in 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 scanner = new Scanner(System.in);

int t = scanner.nextInt();

while(t-- > 0)
{
int count = 0;
int num = scanner.nextInt();
for(int i = 2048; i > 0; i = i / 2)
{
count = count + (num / i);
num = num % i;
if(num == 0) break;
}
System.out.println(count);
}
scanner.close();
}
}
``````
##### Ciel and Receipt CodeChef Solution Review:

In our experience, we suggest you solve this Ciel and Receipt CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Ciel and Receipt CodeChef Solution

Find on CodeChef

##### Conclusion:

I hope this Ciel and Receipt CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions