Problem 6

0

0 votes
Combinatorics, Recursion, Recruit, Number Theory, Easy-Medium, Ready, Mathematics, Approved
Problem

There are 2 criteria to make a difficult password:

1) Choose M numbers out of N given numbers:
= summation of differences between every 2 adjacent M numbers.
For example: if the M numbers are: :
.

2) For given :
= numbers in the interval (both inclusive) that don't have divisors in the M numbers.

Write a program to choose M numbers out of N numbers to maximise the summation
of ().

Input Format
First line contain T, that denotes number of test cases.
For each test case:
Second line contains 2 integers .
Third line contains 2 integers .
Fourth line contains N numbers.

Output Format
For each test case print the maximum value of that could be achieved.

Input Constraints



Sample Input
1
3 2
20 30
3 5 7
Sample Output
10
Time Limit: 4
Memory Limit: 256
Source Limit:
Explanation

The Optimal solution is to choose , .
= difference between adjacent numbers + numbers that don't have divisors in the M numbers = 4 + 6 = .

Numbers that don't have divisors in the M numbers =

Editor Image

?