cswork / OA打开练习工作台

IxlOA #1

Identical Distribution

简单可在线判题

考点(AI 标注)位运算

There are several types of cards, and cardTypes[i] is the number of cards of type i. You may add cards of existing types and choose a number of packs greater than 1 so that every pack contains the same number of cards of each type. Find the minimum number of cards to add.

输入格式

The first line contains n, and the second line contains n positive integers cardTypes. Ranges: 1≤n≤10⁵ (original constraint), 1≤cardTypes[i]≤1000 (the original gives no upper bound on values; this is this site's OJ limit).

输出格式

Output the minimum total number of cards to add.

样例 1

输入:

5
4 7 5 11 15

输出:

4

样例 2

输入:

1
1

输出:

1

样例 3

输入:

1
2

输出:

0

样例说明

For each possible number of packs, compute how many cards each type is short of the next multiple; enumerating pack counts up to the largest existing count plus 1 is enough to cover the optimal solution.