Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define INF 1e9+7
#define rep(i,n) for(ll i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
const int maxn = 10000;
ll mod = INF;

ll d[1000001];
ll n;
ll a[maxn];
vector<map<ll,ll>> m(maxn);
map<ll,ll> lcm;
ll ans=0;

void func(int i,ll k){
    if(k<2)return;
    m[i][d[k]]++;
    //cout <<k<<" "<<d[k]<<endl;
    func(i,k/d[k]);
    return;
}

int main(){
    ll M=0;
    cin >> n;
    rep(i,n){
        cin >> a[i];
        M=max(M,a[i]);
    }

    fill(d,d+1000001,INF);
    d[0]=d[1]=1;
    
    for(int i=2;i<=M;i++){
        if(d[i]!=INF)continue;
        int div=INF;
        if(i%2==0){
            div=2;
        }else{
            for(int tmp=3;tmp*tmp<=i;tmp+=2){
                if(i%tmp==0){
                    div=tmp;
                    break;
                }
            }
            if(div==INF)div=i;
        }
        for(int j=div;j<=M;j+=div){
            if(d[j]==INF)d[j]=div;
        }
    }
    //cout << "check 1"<<endl;
    rep(i,n)func(i,a[i]);
    
    // rep(i,n){
    //     cout << a[i]<<"-----"<<endl;
    //     for(auto ite=m[i].begin();ite!=m[i].end();ite++){
    //         cout << ite->first<<" "<<ite->second<<endl;
    //     }
    // }

    rep(i,n){
        for(auto ite=m[i].begin();ite!=m[i].end();ite++){
            lcm[ite->first]=max(lcm[ite->first],ite->second);
        }
    }
    
    // for(auto ite=lcm.begin();ite!=lcm.end();ite++){
    //     cout << ite->first<<" "<<ite->second<<endl;
    // }
    
    rep(i,n){
        ll add=1;
        //cout << "a[i]= "<<a[i]<<endl;
        for(auto ite=lcm.begin();ite!=lcm.end();ite++){
            ll k=ite->first;
            //cout << ite->first<<":lcm->second= "<<ite->second<<" m[i][ite->first]= "<<m[i][ite->first]<<endl;
            for(int j=0;j<(ite->second)-m[i][ite->first];j++){
                add=add*k%mod;
            }
        }
        //cout << "add= "<<add<<endl;
        ans=(ans+add)%mod;
    }

    cout << ans<<endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:67:13: error: reference to 'lcm' is ambiguous
   67 |             lcm[ite->first]=max(lcm[ite->first],ite->second);
      |             ^~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:58,
                 from a.cc:1:
/usr/include/c++/14/numeric:188:5: note: candidates are: 'template<class _Mn, class _Nn> constexpr std::common_type_t<_Mn, _Nn> std::lcm(_Mn, _Nn)'
  188 |     lcm(_Mn __m, _Nn __n) noexcept
      |     ^~~
a.cc:15:12: note:                 'std::map<long long int, long long int> lcm'
   15 | map<ll,ll> lcm;
      |            ^~~
a.cc:67:33: error: reference to 'lcm' is ambiguous
   67 |             lcm[ite->first]=max(lcm[ite->first],ite->second);
      |                                 ^~~
/usr/include/c++/14/numeric:188:5: note: candidates are: 'template<class _Mn, class _Nn> constexpr std::common_type_t<_Mn, _Nn> std::lcm(_Mn, _Nn)'
  188 |     lcm(_Mn __m, _Nn __n) noexcept
      |     ^~~
a.cc:15:12: note:                 'std::map<long long int, long long int> lcm'
   15 | map<ll,ll> lcm;
      |            ^~~
a.cc:78:22: error: reference to 'lcm' is ambiguous
   78 |         for(auto ite=lcm.begin();ite!=lcm.end();ite++){
      |                      ^~~
/usr/include/c++/14/numeric:188:5: note: candidates are: 'template<class _Mn, class _Nn> constexpr std::common_type_t<_Mn, _Nn> std::lcm(_Mn, _Nn)'
  188 |     lcm(_Mn __m, _Nn __n) noexcept
      |     ^~~
a.cc:15:12: note:                 'std::map<long long int, long long int> lcm'
   15 | map<ll,ll> lcm;
      |            ^~~
a.cc:78:39: error: reference to 'lcm' is ambiguous
   78 |         for(auto ite=lcm.begin();ite!=lcm.end();ite++){
      |                                       ^~~
/usr/include/c++/14/numeric:188:5: note: candidates are: 'template<class _Mn, class _Nn> constexpr std::common_type_t<_Mn, _Nn> std::lcm(_Mn, _Nn)'
  188 |     lcm(_Mn __m, _Nn __n) noexcept
      |     ^~~
a.cc:15:12: note:                 'std::map<long long int, long long int> lcm'
   15 | map<ll,ll> lcm;
      |            ^~~