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 Java8 (OpenJDK 1.8.0) (judge verdict: Accepted)


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			//			solveA();
			//			solveB();
			solveC();
			//			 solveD();
			//			 solveE();
			//			 solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		String numN = next();

		out.println(numN.equals(new StringBuilder(numN).reverse().toString()) ? "Yes" : "No");
	}

	private void solveB() {
		int numA = nextInt();
		int numB = nextInt();
		int numC = nextInt();
		int numD = nextInt();

		int wkRes = Math.min(numB, numD) - Math.max(numA, numC);
		//wkReが0より小さい場合、二人がスイッチを押していた時間の被りはない
		out.println(wkRes >= 0 ? wkRes : 0);
	}

	private void solveC() {
		int numN = nextInt();

		BigDecimal[] times = new BigDecimal[numN];
		for (int i = 0; i < numN; i++) {
			times[i] = new BigDecimal(next());
		}

		/*
		 * 最小公倍数を求める
		 */
		if (times.length == 1) {
			out.println(times[0]);
			return;
		}

		BigDecimal res = BigDecimal.ZERO;
		for (int i = 1; i < times.length; i++) {
			if (i == 1) {
				res = getMinKoubaisu(times[i - 1], times[i]);
			} else {
				res = getMinKoubaisu(res, times[i]);
			}
		}

		out.println(res.longValue());
	}

	private BigDecimal getMinKoubaisu(BigDecimal val1, BigDecimal val2) {
		BigDecimal wk = getMaxKouyaku(val1, val2);
		return (val1.multiply(val2).divide(wk));
	}

	private BigDecimal getMaxKouyaku(BigDecimal val1, BigDecimal val2) {

		BigDecimal wkVal1 = val1.compareTo(val2) <= 0 ? val1 : val2;
		BigDecimal wkVal2 = val1.compareTo(val2) > 0 ? val1 : val2;
		BigDecimal amari = wkVal2.remainder(wkVal1);
		while (!amari.equals(BigDecimal.ZERO)) {
			wkVal2 = wkVal1;
			wkVal1 = amari;
			amari = wkVal2.remainder(wkVal1);
		}

		return wkVal1;
	}

	private void solveD() {
		int numN = nextInt();

		out.println("");
	}

	private void solveE() {
		int numN = nextInt();

		out.println("");
	}

	private void solveF() {
		int numN = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}