CodeChef Solution

Chef Segment CodeChef Solution

We Are Discuss About CODECHEF SOLUTION

Chef Segment CodeChef Solution

Answers will be Uploaded Shortly and it will be Notified on Telegram, So JOIN NOW
JoinScishowEngineerTelegram

Problem

You are given an array  consisting of  integers. You are allowed to rearrange the elements of the array in any order.

A segment [�,�] of the array is considered beautiful if, for every pair (�,�) where �≤�≤�≤�, either ��mod  ��=0 or ��mod  ��=0. Note that mod denotes the modulo operation.

The score of a beautiful segment [�,�] is calculated as follows:

  • score([�,�])=min⁡(��,��+1,…,��)⋅(�−�+1)

Your task is to determine the maximum possible score of a beautiful segment within the given array .

Input Format

  • The first line of input will contain a single integer , denoting the number of test cases.
  • The first line of each test case contains an integer  – the length of the array .
  • The second line of each test case contains  space-separated integers �1,�2,…,��, denoting the array.

Output Format

For each test case, output on a new line, the maximum possible score of a beautiful segment.

Constraints

  • 1≤�≤105
  • 1≤�,��≤105
  • The sum of  over all test cases won’t exceed 3⋅105.
  • The sum of max⁡(��) over all test cases won’t exceed 3⋅105.

Sample 1:

Input

Output

2
4
2 3 4 6
5
4 4 8 10 4
6
16

Explanation:

Test case 1: The array elements can be rearranged as [3,6,2,4].
The beautiful segments are [1,1],[2,2],[3,3],[4,4],[1,2],[2,3],[3,4].
score([1,2])=min⁡(�1,�2)⋅2=6, which is the maximum possible score.

Test case 2: The array elements can be rearranged as [4,4,8,4,10].
The beautiful segment [1,4] has the maximum score of 16.

Answers will be Uploaded Shortly and it will be Notified on Telegram, So JOIN NOW
JoinScishowEngineerTelegram


6 digit code appear after 69 seconds.
 

Wait for Solution



Yhaa You have done it but next? if YOU Want to Get Others Please Visit Here ScishowEngineer   Then Follow US HERE and Join Telegram.

If You Want To Learn Something New Then Visit Our Official Channel YOUTUBE