Given two integers N and Okay, the duty is to examine whether or not N might be represented as sum of Okay distinct optimistic integers.
Input: N = 12, Okay = four
N = 1 + 2 + four + 5 = 12 (12 as sum of four distinct integers)
Input: N = eight, Okay = four
Approach: Consider the collection 1 + 2 + three + … + Okay which has precisely Okay distinct integers with minimal potential sum i.e. Sum = (Okay * (Okay – 1)) / 2. Now, if N < Sum then it isn’t potential to signify N because the sum of Okay distinct optimistic integers but when N ≥ Sum then any integer say X ≥ zero might be added to Sum to generate the sum equal to N i.e. 1 + 2 + three + … + (Okay – 1) + (Okay + X) guaranteeing that there are precisely Okay distinct optimistic integers.
Below is the implementation of the above method:
utilizing namespace std;
bool resolve(int n, int ok)
Second yr Department of Information Technology Jadavpur University
If you want GeeksforGeeks and want to contribute, you can too write an article utilizing contribute.geeksforgeeks.org or mail your article to email@example.com. See your article showing on the GeeksforGeeks major web page and assist different Geeks.
Please Improve this text when you discover something incorrect by clicking on the “Improve Article” button beneath.
Article Tags :
Be the First to upvote.
Please write to us at firstname.lastname@example.org to report any challenge with the above content material.
first_page Check whether or not product of integers from a to b is optimistic , unfavorable or zero
last_page Find the node whose sum with X has most set bits
Share this publish!