922A. Cloning Toys

本文介绍了一种玩具复制机器的工作原理及其使用限制。通过数学分析,解决了如何利用该机器达到特定数量的原版和复制玩具的目标。文章给出了具体的实现代码,并通过几个例子展示了算法的有效性。

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.

Input

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).

Output

Print "Yes", if the desired configuration is possible, and "No" otherwise.

You can print each letter in arbitrary case (upper or lower).

Examples
Input
6 3
Output
Yes
Input
4 2
Output
No
Input
1000 1001
Output
Yes
Note

In the first example, Imp has to apply the machine twice to original toys and then twice to copies.

题意:

一种玩具复制机器可以:

1.用一个original玩具复制产生另外的一个original玩具和一个copies玩具;

2.用一个copies玩具复制产生另外的两个copies玩具;

没有copies玩具这不能进行第二中复制,初始只有一个original玩具

问:能不能产生x个copies玩具和y个original玩具(包括初始的一个original玩具)

思路:

1.如果y==0,无论x对于几都输出“No”;

2.如果y==1,当x==0时输出“Yes”,当x>0时输出No

3.设第一种复制进行n次,第二种复制进行m次,则

  满足  n+1==y  && n+m*2=x:

 

#include<stdio.h>
#include<string.h>
using namespace std;
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int x=m-1;
	int y=n-x;
	if(m==0) printf("No\n");
	else if(m==1){
		if(n==0) printf("Yes\n");
		else printf("No\n");
	}
	else if(y<0) printf("No\n");
	else if(y%2) printf("No\n");
	else printf("Yes\n");
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值