Chunbae's Special Heart
InterviewTime limit1sMemory limit1024 MB
Given N and M, decide whether repeatedly splitting a heart into floor and ceiling halves and keeping one half can end at exactly M grams.
- Level
Medium5 of 10
- Topics
- Divide and conquer, Recursion, Math
- Solved
- No attempts yet
문제
Chunbae has one heart that weighs g. The kind Chunbae wants to split this heart and give a heart weighing g to Nabi as a gift!

Chunbae can split his g heart into 2 hearts. If is even, it splits into two hearts of g each. If is odd, it splits into one heart of g and one heart of g. Then Chunbae must choose one of the two hearts and discard it. He repeats this process until the one heart he keeps weighs g. However, once a heart weighs g, Chunbae cannot split it any further.
Before he splits his heart, Chunbae wants to know whether he can end up with a heart weighing g. Help him find out.
입력
The first line contains the weight of Chunbae's heart and the weight of the heart to give to Nabi, separated by a space. , and are positive integers
출력
If Chunbae can make a heart weighing g, print YES. Otherwise, print NO.