Question: you are given an Integer N. you need to create an array of size N containing positive integers where all elements of array must be

you are given an Integer N. you need to create an array of size N containing positive integers where all elements of array must be distinct.

You are given an integer k. You need to ensure that there are no two elements in the array such that sum of these elements is exactly k.

Your task is to find minimum possible sum of the array that meets the above criteria. Sonce the answer maybe large, return answrr modulo 10^9+7

NOTE;

It is guaranteed that it is always possible to make an array that meets the given conditions.

Input format:

The fitst line contains an Integer N denoting the size of the array that needs to be generated

The next line contains an integer K denoting the sum that can't be equal to sum of a pair in array

1<=N<=10^5

1<=K<=10^5

Sample Input:

2

3

Sample Output:

4

The array can be [1,3] with sum 4 which is the optimal answer for this case

Sample Input:

1

1

Sample output:

1

We can choose array as [1] there is no pair with sum as 1

Sample Input;

4

10

Sample Output:

10

We can choose array [1,2,3,4] as there are no 2 elements with sum 10, so the optimal answer will be 1+2+3+4=10

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!