Language: C++

#include<bits/stdc++.h>
//#include<iostream>
using namespace std;

typedef long long ll;
const int N = 1000006;
const ll MOD = 1000000007;

int n;
int a[N];
bool np[N];

vector<int> prims;

int lcm[N];
ll powermod(ll a,ll b){
	ll ret = 1;
	while(b){
		if(b&1){
			ret *= a;
			ret %= MOD;
		}
		b >>= 1;
		a *= a;
		a %= MOD;
	}
	return ret;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	np[0] = np[1] = true;
	for(int i=4;i<N;i+=2){
		np[i] = true;
	}
	prims.push_back(2);
	for(int i=3;i<N;i+=2){
		if(np[i])continue;
		prims.push_back(i);
		for(ll j=1ll*i*i;j<N;j+=i){
			np[j] = true;
		}
	}

	cin>>n;
	
	for(int i=1;i<=n;i++){
		cin>>a[i];
		int x = a[i];
		for(int j=0;j<(int)prims.size();j++){
			int cnt = 0;
			while(x%prims[j] == 0){
				cnt++;
				x /= prims[j];
			}
			lcm[prims[j]] = max(lcm[prims[j]],cnt);
			if(1ll * prims[j] * prims[j] > x)break;
		}
		if(x > 1){
			lcm[x] = max(lcm[x],1);
		}
	}
	
	ll LCM = 1;
	for(int i=2;i<N;i++){
		ll t = 1;
		for(int j=0;j<lcm[i];j++){
			t *= i;
		}
		LCM *= t;
		LCM %= MOD;
	}
	ll ans = 0;
	for(int i=1;i<=n;i++){
		ll t = LCM;
		int x = a[i];
		for(int j=0;j<(int)prims.size();j++){
			int cnt = 0;
			while(x%prims[j] == 0){
				cnt++;
				x /= prims[j];
			}
			t *= powermod(powermod(prims[j],cnt),MOD-2);
			t %= MOD;
			if(1ll * prims[j] * prims[j] > x)break;
		}
		if(x > 1){
			t*= powermod(x,MOD-2);
			t %= MOD;
		}
		ans += t;
		ans %= MOD;
	}
	
	cout<<ans;
	
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:57:25: error: reference to 'lcm' is ambiguous
   57 |                         lcm[prims[j]] = max(lcm[prims[j]],cnt);
      |                         ^~~
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:5: note:                 'int lcm [1000006]'
   15 | int lcm[N];
      |     ^~~
a.cc:57:45: error: reference to 'lcm' is ambiguous
   57 |                         lcm[prims[j]] = max(lcm[prims[j]],cnt);
      |                                             ^~~
/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:5: note:                 'int lcm [1000006]'
   15 | int lcm[N];
      |     ^~~
a.cc:61:25: error: reference to 'lcm' is ambiguous
   61 |                         lcm[x] = max(lcm[x],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:5: note:                 'int lcm [1000006]'
   15 | int lcm[N];
      |     ^~~
a.cc:61:38: error: reference to 'lcm' is ambiguous
   61 |                         lcm[x] = max(lcm[x],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:5: note:                 'int lcm [1000006]'
   15 | int lcm[N];
      |     ^~~
a.cc:68:31: error: reference to 'lcm' is ambiguous
   68 |                 for(int j=0;j<lcm[i];j++){
      |                               ^~~
/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:5: note:                 'int lcm [1000006]'
   15 | int lcm[N];
      |     ^~~