34 lines
1.3 KiB
Python
34 lines
1.3 KiB
Python
'''
|
||
One cozy afternoon, Lily and her friend Noah decided to buy a large cake from their favorite bakery. They chose the most decadent one, layered with rich frosting and
|
||
fresh berries. After purchasing, the cake was weighed, showing a total weight of n grams. Excited to share it, they hurried home but soon realized they faced a tricky
|
||
problem. Lily and Noah are big fans of even numbers, so they want to divide the cake in such a way that each of the two portions weighs an even number of grams. The
|
||
portions don’t need to be equal, but each must have a positive weight. Since they’re both tired and eager to enjoy the cake, you need to help them determine if it’s
|
||
possible to split it the way they want. Given an integer number n - the weight of cake bought by Lily and Noah, return a string YES, if Lily and Noah can divide the
|
||
cake into two parts, each of them weighing an even number of grams and NO in the opposite case.
|
||
|
||
Example 1
|
||
Input:
|
||
120
|
||
Output:
|
||
YES
|
||
|
||
Example 2
|
||
Input:
|
||
155
|
||
Output:
|
||
NO
|
||
|
||
'''
|
||
|
||
class Solution(object):
|
||
def solve(self, n: int) -> str:
|
||
print(f"n: {n}")
|
||
# Check if n is even and greater than 2
|
||
if n % 2 == 0 and n > 2:
|
||
return "YES"
|
||
else:
|
||
return "NO"
|
||
|
||
s = Solution()
|
||
print(s.solve(120)) # Output: YES
|
||
print(s.solve(155)) # Output: NO |