Maximize Subarray GCD Score - Practice Coding | SlaveCode
0
0123456789
0
0123456789
:
0
0123456789
0
0123456789
3574. Maximize Subarray GCD Score
Hard
50 Points
Array
Math
Enumeration
Number Theory
You are given an array of positive integers nums and an integer k.
You may perform at most k operations. In each operation, you can choose one element in the array and double its value. Each element can be doubled at most once.
The score of a contiguous subarray is defined as the product of its length and the greatest common divisor (GCD) of all its elements.
Your task is to return the maximum score that can be achieved by selecting a contiguous subarray from the modified array.
Note:
Examples
Example 1
Input: nums = [2,4], k = 1
Output: 8
Explanation:
Example 2
Input: nums = [3,5,7], k = 2
Output: 14
Explanation:
Example 3
Input: nums = [5,5,5], k = 1
Output: 15
Explanation:
Constraints
1 <= n == nums.length <= 1500
1 <= nums[i] <= 109
1 <= k <= n
3574. Maximize Subarray GCD Score
Hard
50 Points
Array
Math
Enumeration
Number Theory
You are given an array of positive integers nums and an integer k.
You may perform at most k operations. In each operation, you can choose one element in the array and double its value. Each element can be doubled at most once.
The score of a contiguous subarray is defined as the product of its length and the greatest common divisor (GCD) of all its elements.
Your task is to return the maximum score that can be achieved by selecting a contiguous subarray from the modified array.
Note:
Examples
Example 1
Input: nums = [2,4], k = 1
Output: 8
Explanation:
Example 2
Input: nums = [3,5,7], k = 2
Output: 14
Explanation:
Example 3
Input: nums = [5,5,5], k = 1
Output: 15
Explanation: