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 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 given number can be represented in given a no. of digits in any base
- Check if a number can be represented as a sum of 2 triangular numbers
- Check if given number can be represented as sum of two great numbers
- Check whether the given integers a, b, c and d are in proportion
- Check if a number can be written as sum of three consecutive integers
- Check whether product of integers from a to b is positive , negative or zero
- Check if the sum of distinct digits of two integers are equal
- Check if array contains contiguous integers with duplicates allowed
- Check if N rectangles of equal area can be formed from (4 * N) integers
- Probability for three randomly chosen numbers to be in AP
- Find sum of f(s) for all the chosen sets from the given array
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.