The easiest problems on Codeforces
Today, I would like to share the story behind me, how I’ve solved the most easiest problem on Codeforces.
4A — Watermelon
The description of the problem is straightforward: one day, Pety and Billy went to a market to buy a watermelon. They 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, but at the same time, the parts don't need to be equal.
You have to print “Yes” if they can divide it by the even numbers; otherwise, “No” will be printed.
Let’s see an example, suppose the watermelon weight is 8 kilo then they can easily divide it by 4 and 4 or 6 and 2. In that case, the answer will be Yes.
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
if(n%2==0)
{
printf("YES");
}
else
{
printf("NO");
}
}
This is what comes to mind at that moment: if the weight is even, then the answer will be yes, as we already know that an even number can be formed by two even numbers. Let’s see, 10 if we divide it by 2, then the answer will be 5, which is odd but if we divide by 4 and 6 then our criteria will be fulfilled.
But, when I submitted the code, I got wrong answers several times, and I couldn’t find out why I was getting the wrong answer.
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
if(n%2==0 && n>2)
{
printf("YES");
}
else
{
printf("NO");
}
}
After a couple of submissions, I came to know that if the weight of the watermelon is 2, this case will not pass by my logic.
So, I put another logic inside the if condition, which is that the weight should be greater than 2 and even.