Codechef Problems: Pizza Split (PZSPLIT)
Problem Statement:
Solution:
Given,
N : number of slices in a single pizza
to find: how many pizzas are required for chef and chefina to have equal number of slices ?
to solve this problem we can take 2 cases
case 1 : N is even (i.e., pizza has even number of slices)
in this way chef and chefina can divide equal number of slices
output: 1 (1 pizza is required)
case 2: N is odd
in this way chef and chefina can not divide equal number of slices from a single pizza
they need 2 pizzas for equal distribution
output: 2 (2 pizzas are required)
Code Solution:
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n % 2 == 0) {
cout << 1 << endl;
} else {
cout << 2 << endl;
}
}
Comments
Post a Comment