Given two integers **N** and **M**, the task is to check if it is possible to obtain these values from **X = 1** and **Y = 0** respectively by performing the two operations any number of times::

- Increase X and Y by 1, if and only if x>0.
- Increase Y by 2, if and only if y>0.

**Examples:**

Input:N = 3, M = 4Output:YesExplanation:

Initially X = 1, Y = 0

Operation 1: X = 2, Y = 1

Operation 1: X = 3, Y = 2

Operation 2: X = 3, Y = 4, hence the final values are got so the answer is Yes.

Input:N = 5, M = 2Output:NoExplanation :

Obtaining X = 5 and Y = 2 from X = 1 and Y = 0 is not possible.

**Approach:** The above problem can be solved using the below observations:

- If
**N is less than 2**and**M is not equal to zero**, then getting the final values is not possible, hence the answer is**No**. - Otherwise,
**subtract**N from M and if**M ? 0**and**M is divisible by 2**then the answer is**Yes**. - In all other cases, the answer is
**No**.

Below is the implementation of the above approach:

## C++

`// C++ program for the above approach` `#include <bits/stdc++.h>` `using` `namespace` `std;` `// Function that find given x and y` `// is possible or not` `bool` `is_possible(` `int` `x, ` `int` `y)` `{` ` ` `// Check if x is less than 2 and` ` ` `// y is not equal to 0` ` ` `if` `(x < 2 && y != 0)` ` ` `return` `false` `;` ` ` `// Perform subtraction` ` ` `y = y - x + 1;` ` ` `// Check if y is divisible by 2` ` ` `// and greater than equal to 0` ` ` `if` `(y % 2 == 0 && y >= 0)` ` ` `return` `true` `;` ` ` `else` ` ` `return` `false` `;` `}` `// Driver Code` `int` `main()` `{` ` ` `// Given X and Y` ` ` `int` `x = 5, y = 2;` ` ` `// Function Call` ` ` `if` `(is_possible(x, y))` ` ` `cout << ` `"Yes"` `;` ` ` `else` ` ` `cout << ` `"No"` `;` ` ` `return` `0;` `}` |

*chevron_right*

*filter_none*

## Java

`// Java program for the above approach` `class` `GFG{` ` ` `// Function that find given x and y` `// is possible or not` `static` `boolean` `is_possible(` `int` `x, ` `int` `y)` `{` ` ` `// Check if x is less than 2 and` ` ` `// y is not equal to 0` ` ` `if` `(x < ` `2` `&& y != ` `0` `)` ` ` `return` `false` `;` ` ` ` ` `// Perform subtraction` ` ` `y = y - x + ` `1` `;` ` ` ` ` `// Check if y is divisible by 2` ` ` `// and greater than equal to 0` ` ` `if` `(y % ` `2` `== ` `0` `&& y >= ` `0` `)` ` ` `return` `true` `;` ` ` ` ` `else` ` ` `return` `false` `;` `}` ` ` `// Driver Code` `public` `static` `void` `main(String[] args)` `{` ` ` `// Given X and Y` ` ` `int` `x = ` `5` `, y = ` `2` `;` ` ` ` ` `// Function Call` ` ` `if` `(is_possible(x, y))` ` ` `System.out.println(` `"Yes"` `);` ` ` `else` ` ` `System.out.println(` `"No"` `);` `}` `}` `// This code is contributed by rock_cool` |

*chevron_right*

*filter_none*

## Python

`# Python3 program for the above approach` `# Function that find given x and y` `# is possible or not` `def` `is_possible(x, y):` ` ` ` ` `# Check if x is less than 2 and` ` ` `# y is not equal to 0` ` ` `if` `(x < ` `2` `and` `y !` `=` `0` `):` ` ` `return` `false` ` ` `# Perform subtraction` ` ` `y ` `=` `y ` `-` `x ` `+` `1` ` ` `# Check if y is divisible by 2` ` ` `# and greater than equal to 0` ` ` `if` `(y ` `%` `2` `=` `=` `0` `and` `y >` `=` `0` `):` ` ` `return` `True` ` ` `else` `:` ` ` `return` `False` `# Driver Code` `if` `__name__ ` `=` `=` `'__main__'` `:` ` ` ` ` `# Given X and Y` ` ` `x ` `=` `5` ` ` `y ` `=` `2` ` ` `# Function Call` ` ` `if` `(is_possible(x, y)):` ` ` `print` `(` `"Yes"` `)` ` ` `else` `:` ` ` `print` `(` `"No"` `)` `# This code is contributed by Mohit Kumar` |

*chevron_right*

*filter_none*

## C#

`// C# program for the above approach` `using` `System;` `class` `GFG{` ` ` `// Function that find given x and y` `// is possible or not` `static` `bool` `is_possible(` `int` `x, ` `int` `y)` `{` ` ` `// Check if x is less than 2 and` ` ` `// y is not equal to 0` ` ` `if` `(x < 2 && y != 0)` ` ` `return` `false` `;` ` ` ` ` `// Perform subtraction` ` ` `y = y - x + 1;` ` ` ` ` `// Check if y is divisible by 2` ` ` `// and greater than equal to 0` ` ` `if` `(y % 2 == 0 && y >= 0)` ` ` `return` `true` `;` ` ` ` ` `else` ` ` `return` `false` `;` `}` ` ` `// Driver Code` `public` `static` `void` `Main(` `string` `[] args)` `{` ` ` `// Given X and Y` ` ` `int` `x = 5, y = 2;` ` ` ` ` `// Function Call` ` ` `if` `(is_possible(x, y))` ` ` `Console.Write(` `"Yes"` `);` ` ` `else` ` ` `Console.Write(` `"No"` `);` `}` `}` `// This code is contributed by Ritik Bansal` |

*chevron_right*

*filter_none*

**Output:**

No

**Time Complexity:**** **O(1)**Auxiliary Space: ***O(1)*

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Find the number of jumps to reach X in the number line from zero
- Find the minimum number of steps to reach M from N
- Minimum number of moves to reach N starting from (1, 1)
- Minimize steps to reach K from 0 by adding 1 or doubling at each step
- Find minimum possible values of A, B and C when two of the (A + B), (A + C) and (B + C) are given
- Count of possible permutations of a number represented as a sum of 2's, 4's and 6's only
- Maximum possible elements which are divisible by 2
- Check whether it is possible to convert A into B
- Find all the possible remainders when N is divided by all positive integers from 1 to N+1
- Sum of two numbers if the original ratio and new ratio obtained by adding a given number to each number is given
- Maximize the given number by replacing a segment of digits with the alternate digits given
- Minimum number with digits as 4 and 7 only and given sum
- Find sum of inverse of the divisors when sum of divisors and the number is given
- Check if the number is even or odd whose digits and base (radix) is given
- Find the average of k digits from the beginning and l digits from the end of the given number
- Check whether the given integers a, b, c and d are in proportion
- Print a pair of numbers with the given Sum and Product
- Reduce N to 0 or less by given X and Y operations
- Find the smallest number whose digits multiply to a given number n
- Get the kth smallest number using the digits of the given number

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.