Language: C++

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;
typedef pair<ll  ,ll > pll;

const ll maxn =2e6+5;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define ms(x , y) memset(x , y , sizeof x);
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}

ll n;
ll a[maxn];
ll num[maxn];

int main(){
    migmig
    ms(num , 0);
    cin >> n;
    for (int i = 1 ; i <= n ; i ++){
        cin >> a[i];
        ll boz = a[i];
        for (int j = 2; j*j<=boz ; j ++){
            if(boz%j == 0){
                int mx = 0;
                while(boz%j == 0){
                    boz/=j;
                    mx++;
                }
                num[j] = max(num[j] , mx);
            }
        }
        if(boz!=1){
            num[boz] = 1;
        }
    }
    ll ans = 0;
    ll lcm = 1;
    for (int i = 0 ; i <= 1e6 ; i ++){
        if(num[i]){
            lcm*=pw(i , num[i]);
            lcm%=mod;
        }
    }
    for (int i = 1 ; i <= n ; i ++){
        ans+=lcm*pw(a[i] , mod - 2);
        ans%=mod;
    }
    cout << ans;




    return(0);
}


//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.


Compiler output:
a.cc: In function 'int main()':
a.cc:42:29: error: no matching function for call to 'max(ll&, int&)'
   42 |                 num[j] = max(num[j] , mx);
      |                          ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:42:29: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   42 |                 num[j] = max(num[j] , mx);
      |                          ~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:42:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   42 |                 num[j] = max(num[j] , mx);
      |                          ~~~^~~~~~~~~~~~~