2023-09-01 19:42:45 +08:00
< p > You are given positive integers < code > n< / code > and < code > target< / code > .< / p >
< p > An array < code > nums< / code > is < strong > beautiful< / strong > if it meets the following conditions:< / p >
< ul >
< li > < code > nums.length == n< / code > .< / li >
< li > < code > nums< / code > consists of pairwise < strong > distinct< / strong > < strong > positive< / strong > integers.< / li >
< li > There doesn' t exist two < strong > distinct< / strong > indices, < code > i< / code > and < code > j< / code > , in the range < code > [0, n - 1]< / code > , such that < code > nums[i] + nums[j] == target< / code > .< / li >
< / ul >
2023-12-09 18:42:21 +08:00
< p > Return < em > the < strong > minimum< / strong > possible sum that a beautiful array could have modulo < / em > < code > 10< sup > 9< / sup > + 7< / code > .< / p >
2023-09-01 19:42:45 +08:00
< p > < / p >
< p > < strong class = "example" > Example 1:< / strong > < / p >
< pre >
< strong > Input:< / strong > n = 2, target = 3
< strong > Output:< / strong > 4
< strong > Explanation:< / strong > We can see that nums = [1,3] is beautiful.
- The array nums has length n = 2.
- The array nums consists of pairwise distinct positive integers.
- There doesn' t exist two distinct indices, i and j, with nums[i] + nums[j] == 3.
It can be proven that 4 is the minimum possible sum that a beautiful array could have.
< / pre >
< p > < strong class = "example" > Example 2:< / strong > < / p >
< pre >
< strong > Input:< / strong > n = 3, target = 3
< strong > Output:< / strong > 8
< strong > Explanation:< / strong > We can see that nums = [1,3,4] is beautiful.
- The array nums has length n = 3.
- The array nums consists of pairwise distinct positive integers.
- There doesn' t exist two distinct indices, i and j, with nums[i] + nums[j] == 3.
It can be proven that 8 is the minimum possible sum that a beautiful array could have.
< / pre >
< p > < strong class = "example" > Example 3:< / strong > < / p >
< pre >
< strong > Input:< / strong > n = 1, target = 1
< strong > Output:< / strong > 1
< strong > Explanation:< / strong > We can see, that nums = [1] is beautiful.
< / pre >
< p > < / p >
< p > < strong > Constraints:< / strong > < / p >
< ul >
2023-12-09 18:42:21 +08:00
< li > < code > 1 < = n < = 10< sup > 9< / sup > < / code > < / li >
< li > < code > 1 < = target < = 10< sup > 9< / sup > < / code > < / li >
2023-09-01 19:42:45 +08:00
< / ul >