[Solution] Beautiful Array Codechef Solution
Problem
You're given an array of integers. You need to find the minimum cost of creating another array of integers with the following properties
- for each
- The GCD of adjacent elements of is equal to , i.e, for each
The cost of creating is defined as follows:
Find the minimum possible cost to create the array . Since the answer can be huge print it modulo
Note: You need to minimize the value of total cost of creating the array , and then print this minimum value modulo . For example, suppose there is a way to create the required with a cost of , and another way to do it with a cost of (which is ). The output in this case would be and not .
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
Output Format
For each test case, output on a new line the minimum cost of creating the array , modulo .
No comments:
Post a Comment