Tap here to switch tabs
Problem
Submissions

Problem: Divisible Game

Try to solve the Divisible Game problem.

Statement

You are given an integer array nums.

Alice plays a game where she chooses an integer k > 1 and a contiguous subarray of nums defined by indices l and r where 0≤l≤r<0 \leq l \leq r < nums.length.

For every element nums[i] in the chosen subarray from index l to r:

  • If nums[i] is divisible by k, its value is added to Alice’s score.

  • If nums[i] is not divisible by k, its value is added to Bob’s score.

The score difference is defined as Alice’s score minus Bob’s score.

Alice wants to maximize the score difference. If there are multiple choices of k that achieve the maximum score difference, she chooses the minimum such k.

Return the value of (extmaximumscoredifferenceimesk)(mod109+7)( ext{maximum score difference} imes k) \pmod{10^9 + 7}.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • 1≤1 \leq nums[i] ≤106\leq 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Divisible Game

Try to solve the Divisible Game problem.

Statement

You are given an integer array nums.

Alice plays a game where she chooses an integer k > 1 and a contiguous subarray of nums defined by indices l and r where 0≤l≤r<0 \leq l \leq r < nums.length.

For every element nums[i] in the chosen subarray from index l to r:

  • If nums[i] is divisible by k, its value is added to Alice’s score.

  • If nums[i] is not divisible by k, its value is added to Bob’s score.

The score difference is defined as Alice’s score minus Bob’s score.

Alice wants to maximize the score difference. If there are multiple choices of k that achieve the maximum score difference, she chooses the minimum such k.

Return the value of (extmaximumscoredifferenceimesk)(mod109+7)( ext{maximum score difference} imes k) \pmod{10^9 + 7}.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • 1≤1 \leq nums[i] ≤106\leq 10^6