PDP-23 (2011) - Phase C' - 1 (prevdiv)

View as PDF

Submit solution

Points: 25 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem types
Allowed languages
C, C++, Java, Pascal, Python

prevdiv

You are given a sequence consisting of N positive integers. The task is to find the maximum number in the sequence that is exactly divisible by all the numbers that precede it in the sequence. Obviously, the number that appears first in the sequence is divisible by all its predecessors (because it has none). Thus, if the sequence is not empty, there is always a solution to the problem.

Input Files

The first line of input will contain the number N of elements in the sequence. The second line will contain the N integers of the sequence, separated between them by spaces.

Output Files

The output should consist of a single line containing exactly one integer: the largest number in the sequence that is exactly divisible by all its predecessors in the sequence.

Constraints

1 \le N \le 3.000.000
Execution time limit: 1 sec.
The least common multiple of all the numbers will not exceed 2.000.000.000.

Example of Input - Output Files:

STDIN (prevdiv.in)

10
6 3 7 2 6 21 14 42 63 84

STDOUT (prevdiv.out)

42

Comments

There are no comments at the moment.