Language: C++

#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <unordered_map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<int Modulo = MOD>
struct Mint {

	lint val;
	constexpr Mint(lint v = 0) noexcept : val(v % Modulo) { if (val < 0) val += Modulo; }

	constexpr Mint& operator += (const Mint &r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint &r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint &r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint &r) noexcept {
		lint a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			lint t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}

	constexpr Mint operator + (const Mint &r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint &r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint &r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint &r) const noexcept { return Mint(*this) /= r; }

	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }

	constexpr bool operator == (const Mint &r) const noexcept { return val == r.val; }
	constexpr bool operator != (const Mint &r) const noexcept { return val != r.val; }

	friend ostream &operator << (ostream &os, const Mint<Modulo> &x) noexcept { return os << x.val; }
	friend istream &operator >> (istream &is, Mint<Modulo> &x) noexcept {
		lint tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo> &a, lint n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

template<class T>
inline bool chmax(T &a, const T b) { return a < b && (a = b, true); }

lint modpow(lint a, lint n, lint mod = MOD) {
	lint res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template <int N> class Prime {
private:
	int min_pf[N]; // min_pf[i] = minimum prime factor of i
	int prime[N];
	int cnt = 0;

	// linear sieve https://cp-algorithms.com/algebra/prime-sieve-linear.html
	constexpr void sieve() {
		min_pf[0] = min_pf[1] = -1;
		for (int i = 2; i < N + 1; i++) {
			if (min_pf[i] == 0) {
				prime[cnt++] = i;
				min_pf[i] = i;
			}
			for (int j = 0; j < cnt; ++j) {
				if (prime[j] > min_pf[i] || i * prime[j] >= N + 1) break;
				min_pf[i * prime[j]] = prime[j];
			}
		}
	}

public:
	constexpr Prime() : min_pf(N + 1) { sieve(); }

	vector<pair<lint, int>> factorize(lint n) {
		vector<pair<lint, int>> res;
		lint sz = (lint)min_pf.size();


		int prev = min_pf[n], cnt = -1;
		while (n > 0) {
			int now = min_pf[n];
			n /= now;
			cnt++;
			if (prev != now) {
				res.emplace_back(prev, cnt);
				prev = now;
				cnt = 0;
			}

		}

		return res;
	}

	// verified using boost miller_rabin_test https://wandbox.org/permlink/6YepW3J9SQNFwWxu
	bool isPrime(lint n) {
		if (n < (int)(min_pf.size())) return min_pf[n] == n;
		else if (n == 2 || n == 3) return true;
		else if (n % 2 == 0 || n % 3 == 0) return false;
		else if (n % 6 != 1 && n % 6 != 5) return false;
		for (lint i = 5; i * i <= n; i += 6) {
			if (n % i == 0) return false;
			if (n % (i + 2) == 0) return false;
		}
		return true;
	}
};

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];

	Prime<1000000> P;
	unordered_map<int, int> prime;
	for (int i = 0; i < N; i++) {
		auto p = P.factorize(A[i]);
		for (const auto &e : p) {
			auto itr = prime.find(e.first);
			if (itr == prime.end()) prime[e.first] = e.second;
			else chmax(itr->second, e.second);
		}
	}

	mint l = 1;
	for (const auto &e : prime) l *= modpow(mint(e.first), e.second);

	mint ans = 0;
	for (int i = 0; i < N; i++) ans += mint(1) / A[i];

	cout << ans * l << "\n";

	return 0;
}

Compiler output:
a.cc: In instantiation of 'constexpr Prime<N>::Prime() [with int N = 1000000]':
a.cc:183:17:   required from here
  183 |         Prime<1000000> P;
      |                        ^
a.cc:135:29: error: incompatible types in assignment of 'int' to 'int [1000000]'
  135 |         constexpr Prime() : min_pf(N + 1) { sieve(); }
      |                             ^~~~~~~~~~~~~
a.cc: In instantiation of 'std::vector<std::pair<long long int, int> > Prime<N>::factorize(lint) [with int N = 1000000; lint = long long int]':
a.cc:186:23:   required from here
  186 |                 auto p = P.factorize(A[i]);
      |                          ~~~~~~~~~~~^~~~~~
a.cc:139:40: error: request for member 'size' in '((Prime<1000000>*)this)->Prime<1000000>::min_pf', which is of non-class type 'int [1000000]'
  139 |                 lint sz = (lint)min_pf.size();
      |                                 ~~~~~~~^~~~