Imp likes his plush toy a lot.
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies.
Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies.
The only line contains two integers x and y (0 ≤ x, y ≤ 109) — the number of copies and the number of original toys Imp wants to get (including the initial one).
Print "Yes", if the desired configuration is possible, and "No" otherwise.
You can print each letter in arbitrary case (upper or lower).
6 3
Yes
4 2
No
1000 1001
Yes
In the first example, Imp has to apply the machine twice to original toys and then twice to copies.
题意:有个机器,若把原始玩具放到机器上加工,可以另外得到一个原始玩具和一个复制玩具,若把复制玩具放到机器上加工,可以另外得到两个复制玩具,给出你x个复制玩具和y个原始玩具,让你判断在不丢玩具的情况下,是不是能恰好生产出给出的情况,刚开始时,只有一个原始玩具,y个原始玩具包含刚开始的一个;
思路:当x<y-1时,一定输出No,当x>=y-1时,你可能就会让(x-(y-1)) % 2是不是等于0,若等于0,输出Yes,否则No,但是你已经少考虑特殊细节了,当y(原始玩具)==1时,x只能等于0,当y==0 这种情况就不存在,因为开始时,就有一个原始玩具;
代码:
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
int i,j,x,y;
while(~scanf("%d%d",&x,&y))
{
if(x<y-1||y==0||(y==1&&x>0))
printf("No\n");
else
{
if((x-y+1)%2==0)
printf("Yes\n");
else printf("No\n");
}
}
return 0;
}