Problem:
Score : 300 points

Problem Statement

We have N clocks. The hand of the i-th clock (1≤i≤N) rotates through 360° in exactly T_i seconds.

Initially, the hand of every clock stands still, pointing directly upward.

Now, Dolphin starts all the clocks simultaneously.

In how many seconds will the hand of every clock point directly upward again?

Constraints

1≤N≤100

1≤T_i≤10^{18}

All input values are integers.

The correct answer is at most 10^{18} seconds.

Input

Input is given from Standard Input in the following format:

N
T_1
:
T_N

Output

Print the number of seconds after which the hand of every clock point directly upward again.

Sample Input 1

2
2
3

Sample Output 1

6

We have two clocks. The time when the hand of each clock points upward is as follows:

Clock 1: 2, 4, 6, ... seconds after the beginning

Clock 2: 3, 6, 9, ... seconds after the beginning

Therefore, it takes 6 seconds until the hands of both clocks point directly upward.

Sample Input 2

5
2
5
10
1000000000000000000
1000000000000000000

Sample Output 2

1000000000000000000

Solution in C++14 (Clang 3.8.0) (judge verdict: Accepted)






#if 1

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>

auto& in = std::cin;
auto& out = std::cout;


template<typename T, typename U>
void fill_all_impl(T& arr, const U& v, ...) {
	arr = v;
}
template<typename ARR, typename U>
auto fill_all_impl(ARR& arr, const U& v, std::nullptr_t = nullptr)->decltype(std::begin(arr), void()) {
	for (auto& i : arr) {
		fill_all_impl(i, v);
	}
}
template<typename T, typename U>
void fill_all(T& arr, const U& v) { fill_all_impl(arr, v, nullptr); }



//*********************************************************
// 最大公約数（Greatest Common Divisor）を返す。
// 引数に０がある場合は０を返す。
//*********************************************************
int64_t gcd(int64_t m, int64_t n)
{
	// 引数に０がある場合は０を返す
	if ((0 == m) || (0 == n))
		return 0;

	// ユークリッドの方法
	while ((m != 0)&&(n!=0))
	{
		if (m > n) m = m % n;
		else         n = n % m;
	}
	return (m==0)?n:m;
}//gcd
 //*********************************************************
 // 最小公倍数（Least Common Multiple）を返す。
 // 引数に０がある場合は０を返す。
 //*********************************************************
int64_t lcm(int64_t m, int64_t n)
{
	// 引数に０がある場合は０を返す
	if ((0 == m) || (0 == n))
		return 0;

	if (m == n) {
		return m;
	}

	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm


int32_t N;
int64_t A[1000000];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	for (int32_t i = 0; i < N; ++i)
	{
		in >> A[i];
	}

	for (int32_t i = 1; i < N; ++i)
	{
		A[i]=lcm(A[i-1],A[i]);
	}
	out << A[N- 1]<<endl;

	return 0;
}
#endif




#if 0
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>

auto& in = std::cin;
auto& out = std::cout;

int64_t K;
int64_t N;
std::array<int64_t, 50> A;
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	for (int32_t i = 0; i < N; ++i)
	{
		in >> A[i];
	}
	std::sort(A.begin(), A.begin() + (size_t)N);
	int64_t total_operate = 0;
	for (int32_t dec = N - 1; dec >= 1; dec--)
	{
		int64_t add_count = (A[dec] - A[0]) / (N + 1);
		A[dec] = A[0] + (A[dec] - A[0]) % (N + 1);
		total_operate += add_count;
	}
	for (int32_t i = 0; i < N; ++i)
	{
		A[i] += total_operate;
	}
	std::sort(A.begin(), A.begin() + (size_t)N);

	//この時点で、最大の差がN

	if (A[N-1]<N) {
		out << total_operate << endl; return 0;
	}

	//最大がNになるように全体から引く
	total_operate += N*(A[N - 1] - N);
	if (A[N - 1] - N > 1000000) {
		total_operate -= N;
	}
	for (int32_t i = 0; i < N; ++i)
	{
		A[i] -= (A[N - 1] - N);
	}
	int64_t last_index = N - 1;
	for (;;)
	{
		++total_operate;
		A[last_index] -= N;
		for (int32_t i = 0; i < N; ++i)
		{
			if (i != last_index) {
				A[i]++;
			}
		}
		--last_index;
		if (last_index < 0) { last_index += N; }
		if (std::all_of(A.begin(), A.begin() + (size_t)N, [](int64_t v) {return v < N; })) {
			out << total_operate << endl; return 0;
		}
	}

	////値が二種類

	//int32_t big_count = std::count(A, A + N, A[last_index]);
	//total_operate += (A[last_index] - (N-big_count)) - (N - 1);
	//total_operate -= (N - big_count);
	//out << total_operate << endl; return 0;
}
#endif