Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USACO # 3 Bessie has woken up on a strange planet. In this planet, there are N ( 1 < = N < = 1

USACO #3 Bessie has woken up on a strange planet. In this planet, there are N (1<= N <=104) months, with a1,..., aN days, respectively (1<= ai <=4*109, 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 ai mod L.
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++).
Input Format (input arrives from the terminal / stdin):
The first line contains a single integer N. The second line contains N space-separated integers, a1,..., aN.
Output Format (print output to the terminal / stout):
A single integer, the sum of all possible values of L
Sample Input:
12
312831303130313130313031
Sample Output:
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 4*7=28 days long, and each month is either 0,2, or 3 mod 7.
Sample Input:
4
31352829
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 4*6=24 days long, and each month is either 1,4, or 5 mod 6.
Scoring:
Inputs 3~4: 1<= ai <=106
Inputs 5-14: No additional constraints
Please show me that your code shows the correct output for each of the following sample input

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=+1. How similar is the source to the audience?

Answered: 1 week ago

Question

5. Understand how cultural values influence conflict behavior.

Answered: 1 week ago

Question

8. Explain the relationship between communication and context.

Answered: 1 week ago