Smallest value of N such that the sum of all natural numbers from K to N is at least X

Smallest value of N such that the sum of all natural numbers from K to N is at least X
Given two positive integers X and K, the task is to find the minimum value of N possible such that the sum of all natural numbers from the range [K, N] is at least X. If no possible value of N exists, then print -1.
Examples:

Input: K = 5, X = 13Output: 7Explanation: The minimum possible value is 7. Sum = 5 + 6 + 7 = 18, which is at least 13.
Input: K = 3, X = 15Output: 6

Naive Approach: The simplest approach to solve this problem is to check for every value in the range [K, X] and return the first value from this range which has sum of the first N natural numbers at least X.Below is the implementation of the above approach:

C++

  
#include
using namespace std;
  

void minimumNumber(int K, int X)
{
    
    if (K > X) {
        cout X) {
        cout