Watermelon Codeforces Solution C++ πΈπΆππ πΈππ ππΆππΆππΎππ Codeforces Beta Round 4
Watermelon Codeforces Solution
Question link: Watermelon Codeforces.
For Beginners step by step procedure to solve this Watermelon Codeforces.
- Understand the question
- Try to think of other test cases than present in the question.
- Try to write a pseudo code for it.
Question:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that, the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however, they faced a hard problem.
Pete and Billy are great fans of even numbers, thatβs why they want to divide the watermelon in such a way that each of the two parts weighs an even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, thatβs why you should help them and find out if they can divide the watermelon in the way they want. For sure, each of them should get a part of the positive weight.
Input:
An integer w
where w is between 1 and 100, this is the weight of the watermelon.
Output:
Print YES if it can be divided into two parts, otherwise NO.
Solution:
Hint 1: When can a whole number be divided into two parts?
Hint 2: Think of an Odd / Even Case.
Intuition for Watermelon Codeforces Solution: So, We have to divide the watermelons into two equal halves, to divide the watermelon we need to check whether the given number is Odd or Even and also to make sure the result after dividing them is also even.
Important: Since we have also to make sure that the result is also Even, All even numbers greater than 2 will have a result even after diving it into equal halves. |
Steps to Solve Watermelon Codeforces Solution:
- Take input using cin in a variable C++.
- Check if the number is divisible by 2 and also it is greater than equal to 2.
- Print Yes / No Accordingly.
Β
C++ Watermelon Codeforces Solution:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int w;
cin>>w;
if(w%2 ==0 && w >= 2)
{
cout<<"YES";
}
else
{
cout<<"NO";
}
return 0;
}
Thank You!
Visit to See More Coding Solutions.
One thought on βWatermelon Codeforces Solution C++ πΈπΆππ πΈππ ππΆππΆππΎππ Codeforces Beta Round 4β