Maximum MOD
Practice
3.3 (3 votes)
Observation
Basic math
Algorithms
Basics of greedy algorithms
Math
Problem
80% Success 580 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given an array $$A$$ that consists of $$N$$ elements.
Assume that a function \(F(x) = (x\:mod\:A_1) + (x\:mod\:A_2)\:+\: ..... \:+\:(x\:mod\:A_N)\), for some non-negative integer $$x$$. You are required to find the maximum possible value of the function $$F(x)$$.
Here, \(X\:mod\:Y\) 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
\(1 \le T \le 1000\\ 1 \le N \le 200000\\ 1 \le A_i \le 1000000000\)
It is guaranteed that the sum of $$N$$ over $$T$$ test cases does not exceed $$1e6$$.
Submissions
Please login to view your submissions
Similar Problems
Points:20
4 votes
Tags:
Easy
Points:20
111 votes
Tags:
MathematicsEasyMathematicsMathamatics
3.Bot Game
Points:20
4 votes
Tags:
Easy
Editorial