Given three integers N, A and B, the task is to find whether N can be represented as sum of A’s and B’s.
Input: N = 11, A = 2, B = 3
2 + 2 + 2 + 2 + 3 = 11
Input: N = 8, A = 3, B = 7
Approach: An efficient solution is to call a recursive function starting with zero (because zero is always possible). If function call is fun(x) then recursively call fun(x + a) and fun(x + b) (because if x is possible then x + a and x + b are also possible). Return out of the function if x > n.
Below is the implementation of the above approach:
- Check if N can be represented as sum of squares of two consecutive integers
- Check whether a number can be represented as sum of K distinct positive integers
- Number of ways in which N can be represented as the sum of two positive integers
- Check whether a number can be represented by sum of two squares
- Check if a number can be represented as sum of non zero powers of 2
- Check if a number can be represented as a sum of 2 triangular numbers
- Check whether a number can be represented by the product of two squares
- Check whether a number can be represented as difference of two squares
- Check if given number can be represented as sum of two great numbers
- Check if a given number can be represented in given a no. of digits in any base
- Check if the XOR of an array of integers is Even or Odd
- Check whether the given integers a, b, c and d are in proportion
- Check whether product of integers from a to b is positive , negative or zero
- Check if a number can be written as sum of three consecutive integers
- Check if the sum of distinct digits of two integers are equal
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.