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
题意:你最初只有一个玩具,现在有个机器可以实现两种操作:复制原件得到1新原件+1副本,复制副本得到2副本。给你想要得到的原件数和副本数,问你是否可以恰好得到,玩具不可以扔掉。
思路:由于原件只能由原件得来,一定先处理原件,本身已经有一个原件,所以额外需要的是y-1个,同时会多出来y-1个副本,此时判断副本数与x的大小,超过x直接判No,小于时判断两者之差是不是偶数,因为此时原件已经够了,只能通过第二个操作实现。剩下的是边界情况特判即可。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<string>
#include<sstream>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#define ll long long
using namespace std;
ll x,y;
int main()
{
while(~scanf("%lld%lld",&x,&y))
{
if(x==0&&y==1){printf("Yes\n");continue;}
if(y==0||y==1){printf("No\n");continue;} //y==0时必然不存在答案
ll cp=y-1; //满足原件时,多出来的副本个数
if(cp>x)printf("No\n");
else
{
if((x-cp)%2==0)printf("Yes\n");
else printf("No\n");
}
}
return 0;
}