# Chocolate Feast problem Hackerrank coderinme

#### Chocolate Feast problem Hackerrank

Here comes a benefit for chocolate lovers. The problem here is as beneficial to the one who can calculate it correctly and logically. Now, the problem is to find the number of chocolate if there is a condition that for every n wrapper they can get 1 more chocos like, Bobby has 4 dollars that he uses to buy 4 chocolates at 1 dollar a piece, he can trade in the 2 wrappers to buy 1 more chocolates. Now he has 4 more wrappers that he can trade in for 2 more chocolate. Because he only has 2 wrappers left at this point and he can take 1 more, he was only able to eat a total of 7 pieces of chocolate. 4+2+1. Kind-of tricky but interesting and beneficial.
main question source

##### Question format may be as follows

For a time being let’s say, Little Bobby loves chocolate, and he frequently goes to his favourite store, Penny Auntie, with n dollars to buy chocolates. Each chocolate has a flat cost of ‘c’ dollars, and the store has a promotion where they allow you to trade in ‘m’ chocolate wrappers in exchange for the free piece of chocolate.
For example, if m=2 and Bobby have n=4 dollars that he uses to buy 4 chocolates at a c=1 dollar a piece, he can trade in the 4 wrappers to buy 2 more chocolates. Now he has 2 more wrappers that he can trade in for 1 more chocolate. Because he only has 1 wrapper left at this point and 1<m, he was only able to eat a total of 7 pieces of chocolate.

So the data required is like:

##### Input

Given n, c, and m for t trips to the store, can you determine how many chocolates Bobby eats during each trip?

``````#include <math.h>
#include <stdio.h>
int main(){
int t;
scanf("%d",&t);
for(int a0 = 0; a0 < t; a0++){
int n;
int c;
int m;
scanf("%d %d %d",&n,&c,&m);
int  choc=n/c;
int mc=n/c;
do{
if(choc>=m)
{
choc-=m;
choc+=1;
mc+=1;   }
} while(choc>=m);
printf("%d\n",mc);

}

return 0;
}
``````
``````for _ in range(input()):
n, c, m = map(int, raw_input().split())
chocs = n / c
wraps = chocs
while wraps >= m:
chocs += wraps/m
wraps = wraps/m + wraps%m
print chocs``````
``````#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
int t;
long int n,c,m;
cin>>t;
for(int i=0;i<t;++i)
{
cin>>n>>c>>m;
long int x=n/c;
long int count=x;
while(x>=m)
{
count=count+(x/m);
x=(x/m)+x%m;

}
cout<<count<<endl;
}
return 0;
}``````

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin@coderinme.com

### hasectic

A web developer(Front end and Back end), and DBA at csdamu.com. Currently working as Salesforce Developer @ Tech Matrix IT Consulting Private Limited. Check me @about.me/s.saifi