Language: C++


template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}
 
  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }
 
  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}
 
  Mint inv(){return pow(MOD-2);}
 
  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}
 
  Mint operator+(Mint a) const{return Mint(v)+=a;}
  Mint operator-(Mint a) const{return Mint(v)-=a;}
  Mint operator*(Mint a) const{return Mint(v)*=a;}
  Mint operator/(Mint a) const{return Mint(v)/=a;}
 
  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}
 
  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}
 
  static Mint comb(long long n,int k){
    Mint num(1),dom(1);
    for(int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}
 
 
template<typename T>
map<T, int> factorize(T x){
  map<T, int> res;
  for(int i=2;i*i<=x;i++){
    while(x%i==0){
      x/=i;
      res[i]++;
    }
  }
  if(x!=1) res[x]++;
  return res;
}

int main()
{
    int N;
    scanf("%d", &N);
    Int A[N];
    for(int i = 0; i < N; ++i) scanf("%lld", &A[i]);

    map<Int,Int> LCM_fct;
    for(auto a : A){
        for(auto p:factorize(a)){
            if(LCM_fct[p.first] < p.second) LCM_fct[p.first] = p.second;
        }
    }

    using M = Mint<Int>;
    M lcm = 1LL;
    for(auto p:LCM_fct) {
        lcm *= M(p.first).pow(p.second);
    }

    M ans(0);
    for(auto a:A){
        ans += lcm/M(a);
    }
    printf("%lld\n", ans.v);
    return 0;
}

Compiler output:
a.cc:52:1: error: 'ostream' does not name a type
   52 | ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}
      | ^~~~~~~
a.cc:56:1: error: 'map' does not name a type
   56 | map<T, int> factorize(T x){
      | ^~~
a.cc: In function 'int main()':
a.cc:71:5: error: 'scanf' was not declared in this scope
   71 |     scanf("%d", &N);
      |     ^~~~~
a.cc:72:5: error: 'Int' was not declared in this scope; did you mean 'int'?
   72 |     Int A[N];
      |     ^~~
      |     int
a.cc:73:47: error: 'A' was not declared in this scope
   73 |     for(int i = 0; i < N; ++i) scanf("%lld", &A[i]);
      |                                               ^
a.cc:75:5: error: 'map' was not declared in this scope
   75 |     map<Int,Int> LCM_fct;
      |     ^~~
a.cc:75:18: error: 'LCM_fct' was not declared in this scope
   75 |     map<Int,Int> LCM_fct;
      |                  ^~~~~~~
a.cc:76:18: error: 'A' was not declared in this scope
   76 |     for(auto a : A){
      |                  ^
a.cc:77:20: error: 'factorize' was not declared in this scope
   77 |         for(auto p:factorize(a)){
      |                    ^~~~~~~~~
a.cc:82:23: note: invalid template non-type parameter
   82 |     using M = Mint<Int>;
      |                       ^
a.cc:83:5: error: 'M' was not declared in this scope
   83 |     M lcm = 1LL;
      |     ^
a.cc:85:9: error: 'lcm' was not declared in this scope
   85 |         lcm *= M(p.first).pow(p.second);
      |         ^~~
a.cc:88:6: error: expected ';' before 'ans'
   88 |     M ans(0);
      |      ^~~~
      |      ;
a.cc:89:16: error: 'A' was not declared in this scope
   89 |     for(auto a:A){
      |                ^
a.cc:90:9: error: 'ans' was not declared in this scope
   90 |         ans += lcm/M(a);
      |         ^~~
a.cc:90:16: error: 'lcm' was not declared in this scope
   90 |         ans += lcm/M(a);
      |                ^~~
a.cc:92:22: error: 'ans' was not declared in this scope
   92 |     printf("%lld\n", ans.v);
      |                      ^~~
a.cc:92:5: error: 'printf' was not declared in this scope
   92 |     printf("%lld\n", ans.v);
      |     ^~~~~~
a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 |