Tap here to switch tabs
Problem
Submissions

Problem: Apply Operations to Maximize Score

Try to solve the Apply Operations to Maximize Score problem.

Statement

You are given an array nums of nn positive integers and an integer k.

Initially, your score is 11. You may perform the following operation at most k times:

  1. Select a non empty subarray nums[l...r] where 0≤l≤r<n0 \leq l \leq r < n that has not been previously selected.

  2. Identify the element nums[i] in the subarray that has the maximum prime score. If multiple elements have the highest prime score, select the one with the smallest index i.

  3. Multiply your current score by nums[i].

The prime score of an integer is defined as the number of its distinct prime factors. For instance, the prime score of 300=22×3×52300 = 2^2 \times 3 \times 5^2 is 33, as its distinct prime factors are 22, 33, and 55.

Return the maximum possible score achievable after applying at most k operations. Since the result may be very large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \leq nums.length ==n≤105== n \leq 10^5

  • 1≤1 \leq nums[i] ≤105\leq 10^5

  • 1≤1 \leq k ≤min⁡(n⋅(n+1)/2,109)\leq \min(n \cdot (n + 1) / 2, 10^9)

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Apply Operations to Maximize Score

Try to solve the Apply Operations to Maximize Score problem.

Statement

You are given an array nums of nn positive integers and an integer k.

Initially, your score is 11. You may perform the following operation at most k times:

  1. Select a non empty subarray nums[l...r] where 0≤l≤r<n0 \leq l \leq r < n that has not been previously selected.

  2. Identify the element nums[i] in the subarray that has the maximum prime score. If multiple elements have the highest prime score, select the one with the smallest index i.

  3. Multiply your current score by nums[i].

The prime score of an integer is defined as the number of its distinct prime factors. For instance, the prime score of 300=22×3×52300 = 2^2 \times 3 \times 5^2 is 33, as its distinct prime factors are 22, 33, and 55.

Return the maximum possible score achievable after applying at most k operations. Since the result may be very large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \leq nums.length ==n≤105== n \leq 10^5

  • 1≤1 \leq nums[i] ≤105\leq 10^5

  • 1≤1 \leq k ≤min⁡(n⋅(n+1)/2,109)\leq \min(n \cdot (n + 1) / 2, 10^9)