Maximum MOD

3.3

3 votes
, Observation, Basic Math, Algorithms, Basics of Greedy Algorithms, Math
Problem

You are given an array A that consists of N elements.
Assume that a function F(x)=(xmodA1)+(xmodA2)+.....+(xmodAN), for some non-negative integer x. You are required to find the maximum possible value of the function F(x).

Here, XmodY denotes the remainder of the X division by Y.

Input format

  • The first line contains an integer T denoting the number of test cases.
  • The first line of each test case contains an integer N denoting the size of array A.
  • The second line of each test case contains N space-separated integers denoting array A.

Output format

For each test case, print the maximum possible value of F(x) in a new line.

Constraints

1T10001N2000001Ai1000000000

It is guaranteed that the sum of N over T test cases does not exceed 1e6.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For the first testcase, we can take x = 9599. Thus, the maximum possible value of F(x) is 26. 

For the second testcase, we can take x = 159. Thus, the maximum possible value of F(x) is 14. 

Editor Image

?