# Opera & B2G1 siamsplash.5 DIU Take-Off Programming...

Category: Simple Math

Problem Analysis:

Observation: This problem can be solved by simple iteration or by using mathematical observations. As the problem category is Simple Math, let’s solve it with math.

• Let’s forget about the term “Buy 2 Get 1”. How many pizzas actually you can buy?

• If for buying $2$ pizzas, you’re getting $1$ additional pizza for free, then for buying $C$ pizzas, how many additional pizzas will you get?

Solution Idea:

• If the pizza price is $X$, and the dollar you have is $M$. Then the total number of pizzas you can buy is, $C = M/X$

• For example, $M = 20$, $X = 6$, then $C = (20/6) = 3$.

• Now you have the $C$. So, the additional pizzas you will get will be,

$=C/2$

$= (M/X)/2$ [ As, $C = M/X$]

$= M/(2*X)$

• So, total number of pizzas will be $= (M/X) + {M/(2*X)}$

Special Thanks: Md. Albin Hossain

Source Code:
#include <stdio.h>
int main(){
int test_case;
scanf("%d", &test_case);
while(test_case--){
int m, x;
scanf("%d %d", &m, &x);
int pizza_count = (m / x) + (m / (2 * x));
printf("%d\n", pizza_count);
}
return 0;
} Math

### Statistics

92% Solution Ratio
steinumEarliest, 6M ago
user.3193Fastest, 0.0s
Monjurul.9781Lightest, 4.9 MB
ItzRAYShortest, 93B 