2019: [USACO 2024 January Contest Silver] Problem 3. Cowlendar

文件提交:无需freopen 内存限制:256 MB 时间限制:2.000 S
评测方式:普通裁判 命题人:
提交:3 解决:1

题目描述

Bessie has woken up on a strange planet. In this planet, there are N (1N104) months, with a1,,aN days, respectively (1ai4109, all ai are integers). In addition, on the planet, there are also weeks, where each week is L days, with L being a positive integer. Interestingly, Bessie knows the following:

  • For the correct L, each month is at least 4 weeks long.
  • For the correct L, there are at most 3 distinct values of aimodL.

Unfortunately, Bessie has forgotten what L is! Help her by printing the sum of all possible values of L.

Note that the large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long long" in C/C++).

输入

The first line contains a single integer N. The second line contains N space-separated integers, a1,,aN.

输出

A single integer, the sum of all possible values of L.

样例输入

12
31 28 31 30 31 30 31 31 30 31 30 31

样例输出

28

提示

The possible values of L are 1, 2, 3, 4, 5, 6, and 7. For example, L=7 is valid because each month is at least length 47=28 days long, and each month is either 0, 2, or 3 mod 7.

SAMPLE INPUT:

4

31 35 28 29

SAMPLE OUTPUT:

23

The possible values of L are 1, 2, 3, 4, 6, and 7. For example, L=6 is valid because each month is at least length 46=24 days long, and each month is either 1, 4, or 5 mod 6.

SCORING:

  • Inputs 3-4: 1ai106
  • Inputs 5-14: No additional constraints

来源/分类