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 if a number can be represented as sum of non zero powers of 2
- Check whether a number can be represented by sum of two squares
- Check if given number can be represented as sum of two great numbers
- Check if a number can be represented as a sum of 2 triangular numbers
- Check if a given number can be represented in given a no. of digits in any base
- Check whether the given integers a, b, c and d are in proportion
- Probability for three randomly chosen numbers to be in AP
- 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
- Ways to choose balls such that at least one ball is chosen
- Check if array contains contiguous integers with duplicates allowed
- Probability that a random pair chosen from an array (a[i], a[j]) has the maximum sum
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.