Language: C++

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef vector<vector<P>> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<ll> vec;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}

template<int MOD> struct modint {
    long long val;

    constexpr modint(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) v += MOD;
    }
    constexpr modint operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    
    constexpr int getmod() { return MOD; }
    constexpr modint operator + (const modint& r) const noexcept { return modint(*this) += r; }
    constexpr modint operator - (const modint& r) const noexcept { return modint(*this) -= r; }
    constexpr modint operator * (const modint& r) const noexcept { return modint(*this) *= r; }
    constexpr modint operator / (const modint& r) const noexcept { return modint(*this) /= r; }
    constexpr modint& operator += (const modint& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr modint& operator -= (const modint& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr modint& operator *= (const modint& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr modint& operator /= (const modint& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const modint& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const modint& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const modint<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr istream& operator >> (istream &is, modint<MOD>& x) noexcept {
        return is >> x.val;
    }
    friend constexpr modint<MOD> modpow(const modint<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = modint<MOD>;
typedef vector<mint> mvec;
typedef vector<vector<mint>> mvvec;

vector<int> pri;
bool inited=false;
void init(int x){ // x以下の素数テーブルを生成 O(n)
    vector<bool> flag(x+1,false);
    for(int i = 2; i <= x; i++){
        if(flag[i]) continue;
        pri.emplace_back(i);
        for(int j = i; j <= x; j+=i) flag[j] = true;
    }
    inited=true;
}

pvec prime_factorize(int n) {
    pvec res;
    if(inited){
        for(int &p : pri){
            if(n % p != 0) continue;
            int cnt = 0;
            while(n % p == 0) { ++cnt; n /= p; }
            res.emplace_back(p, cnt);
        }
    }
    else{
        for(int p = 2; p * p <= n; ++p){
            if(n % p != 0) continue;
            int cnt = 0;
            while(n % p == 0) { ++cnt; n /= p; }
            res.emplace_back(p, cnt);
        }
    }
    if (n!=1) res.emplace_back(n, 1); // n^1/2よりも大きな素数
    return res;
} // 素数判定 [pvec].size()==1 && [pvec].sc == 1

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n;
    cin>>n;
    vector<int> a(n);
    REP(i,n) cin >> a[i];
    init(1010);
    vector<long long> num(1100000, 0);
    rep(i,n){
        auto x=prime_factorize(a[i]);
        for(auto p:x) chmax(num[p.fs],p.sc);
    }
    mint lcm=1;
    rep(i,1100000){
        lcm*=modpow(mint(i),num[i]);
    }
    mint ans=0;
    rep(i,n){
        ans+=lcm/a[i];
    }
    cout<<ans<<endl;
    
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:12: error: 'class std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >' has no member named 'first'
   11 | #define fs first
      |            ^~~~~
a.cc:145:35: note: in expansion of macro 'fs'
  145 |         for(auto p:x) chmax(num[p.fs],p.sc);
      |                                   ^~
a.cc:12:12: error: 'class std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >' has no member named 'second'
   12 | #define sc second
      |            ^~~~~~
a.cc:145:41: note: in expansion of macro 'sc'
  145 |         for(auto p:x) chmax(num[p.fs],p.sc);
      |                                         ^~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/c++allocator.h:33,
                 from /usr/include/c++/14/bits/allocator.h:46,
                 from /usr/include/c++/14/string:43,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:2:
/usr/include/c++/14/bits/new_allocator.h: In instantiation of 'void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >; _Args = {long long int&, long long int&}; _Tp = std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >]':
/usr/include/c++/14/bits/alloc_traits.h:575:17:   required from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >; _Args = {long long int&, long long int&}; _Tp = std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >; allocator_type = std::allocator<std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > > >]'
  575 |           __a.construct(__p, std::forward<_Args>(__args)...);
      |           ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:117:30:   required from 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {long long int&, long long int&}; _Tp = std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >; _Alloc = std::allocator<std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > > >; reference = std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >&]'
  117 |             _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
      |             ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  118 |                                      std::forward<_Args>(__args)...);
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:115:29:   required from here
  115 |             res.emplace_back(p, cnt);
      |             ~~~~~~~~~~~~~~~~^~~~~~~~
/usr/include/c++/14/bits/new_allocator.h:191:11: error: no matching function for call to 'std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >::vector(long long int&, long long int&)'
  191 |         { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53:
/usr/include/c++/14/bits/stl_vector.h:707:9: note: candidate: 'template<class _InputIterator, class> std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&) [with <template-parameter-2-2> = _InputIterator; _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >]'
  707 |         vector(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:707:9: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/14/bits/stl_algobase.h:65,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_iterator_base_types.h: In substitution of 'template<class _InIter> using std::_RequireInputIter = std::__enable_if_t<((bool)std::is_convertible<typename std::iterator_traits< <template-parameter-1-1> >::iterator_category, std::input_iterator_tag>::value)> [with _InIter = long long int]':
/usr/include/c++/14/bits/stl_vector.h:705:9:   required from 'void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >; _Args = {long long int&, long long int&}; _Tp = std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >]'
  705 |                typename = std::_RequireInputIter<_InputIterator>>
      |                ^~~~~~~~
/usr/include/c++/14/bits/alloc_traits.h:575:17:   required from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >; _Args = {long long int&, long long int&}; _Tp = std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >; allocator_type = std::allocator<std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > > >]'
  575 |           __a.construct(__p, std::forward<_Args>(__args)...);
      |           ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:117:30:   required from 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {long long int&, long long int&}; _Tp = std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >; _Alloc = std::allocator<std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > > >; reference = std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >&]'
  117 |             _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
      |             ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  118 |                                      std::forward<_Args>(__args)...);
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:115:29:   required from here
  115 |             res.emplace_back(p, cnt);
      |             ~~~~~~~~~~~~~~~~^~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_types.h:252:57: error: no type named 'iterator_category' in 'struct std::iterator_traits<long long int>'
  252 |                                    input_iterator_tag>::value>;
      |                                                         ^~~~~
/usr/include/c++/14/bits/new_allocator.h: In instantiation of 'void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >; _Args = {long long int&, long long int&}; _Tp = std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >]':
/usr/include/c++/14/bits/alloc_traits.h:575:17:   required from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >; _Args = {long long int&, long long int&}; _Tp = std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >; allocator_type = std::allocator<std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > > >]'
  575 |           __a.construct(__p, std::forward<_Args>(__args)...);
      |           ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:117:30:   required from 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {long long int&, long long int&}; _Tp = std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >; _Alloc = std::allocator<std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > > >; reference = std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >&]'
  117 |             _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
      |             ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  118 |                                      std::forward<_Args>(__args)...);
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:115:29:   required from here
  115 |             res.emplace_back(p, cnt);
      |             ~~~~~~~~~~~~~~~~^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:678:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::initializer_list<_Tp>, const allocator_type&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; allocator_type = std::allocator<std::pair<long long int, long long int> >]'
  678 |       vector(initializer_list<value_type> __l,
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:678:43: note:   no known conversion for argument 1 from 'lon