Language: C++

#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std;
using ll = long long;
using P = pair<int,int>;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }

  // combination
  mint choose(int n, int a) {
      mint x = 1, y = 1;
      rep(i,a) {
          x *= n-i;
          y *= i+1;
      }
      return x / y;
  }
};

struct Sieve {
    int n;
    // f[i]はiが素数であればi
    // iが素数でなければ約数の中の最小の素数
    vector<int> f, primes;
    Sieve(int n = 1): n(n), f(n+1){
        f[0] == f[1] == -1;
        for(int i = 2; i <= n; ++i){
            if(f[i]) continue;
            primes.push_back(i);
            f[i] = i;
            for(int j = 2 * i; j <= n; j += i) {
                if (!f[j]) f[j] = i;
            }
        }
    }
    // 素数判定
    bool is_prime(int x) { return f[x] == x;}
    // 約数の列挙
    vector<int> prime_divisor(int x) {
        vector<int> res;
        while(x != 1) {
            res.push_back(f[x]);
            x /= f[x];
        }
        return res;
    }
    // 素因数分解
    vector<P> prime_factor(int x) {
        vector<int> pd = prime_divisor(x);
        if(pd.size() == 0) return {};
        vector<P> res(1, P(f[0], 0));
        for(auto i: pd) {
            if(res.back().first == i){
                res.back().second++;
            }
            else {
                res.emplace_back(P(i, 1));
            }
        }
        return res;
    }
};

int main() {
    Sieve sieve(1e6);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    map<int,int> mp;
    rep(i, n) {
        auto pf = sieve.prime_factor(a[i]);
        for(auto x: pf){
            mp[x.first] = max(mp[x.first], x.second);
        }
    }

    mint lcm = 1;
    for(auto p: mp){
        rep(i, p.second)
            lcm *= p.first;
    }
    mint ans = 0;
    rep(i, n){
        mint b = lcm / a[i];
        ans += b;
    }
    cout << ans.x << endl;

    return 0;
}

Compiler output:
a.cc:1:26: warning: extra tokens at end of #include directive
    1 | #include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std;
      |                          ^
a.cc:3:11: error: 'pair' does not name a type
    3 | using P = pair<int,int>;
      |           ^~~~
a.cc: In member function 'mint mint::choose(int, int)':
a.cc:57:11: error: 'i' was not declared in this scope
   57 |       rep(i,a) {
      |           ^
a.cc:57:7: error: 'rep' was not declared in this scope
   57 |       rep(i,a) {
      |       ^~~
a.cc: At global scope:
a.cc:69:5: error: 'vector' does not name a type
   69 |     vector<int> f, primes;
      |     ^~~~~~
a.cc:84:5: error: 'vector' does not name a type
   84 |     vector<int> prime_divisor(int x) {
      |     ^~~~~~
a.cc:93:5: error: 'vector' does not name a type
   93 |     vector<P> prime_factor(int x) {
      |     ^~~~~~
a.cc: In constructor 'Sieve::Sieve(int)':
a.cc:70:29: error: class 'Sieve' does not have any field named 'f'
   70 |     Sieve(int n = 1): n(n), f(n+1){
      |                             ^
a.cc:71:9: error: 'f' was not declared in this scope
   71 |         f[0] == f[1] == -1;
      |         ^
a.cc:74:13: error: 'primes' was not declared in this scope
   74 |             primes.push_back(i);
      |             ^~~~~~
a.cc: In member function 'bool Sieve::is_prime(int)':
a.cc:82:35: error: 'f' was not declared in this scope
   82 |     bool is_prime(int x) { return f[x] == x;}
      |                                   ^
a.cc: In function 'int main()':
a.cc:112:5: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
  112 |     cin >> n;
      |     ^~~
      |     std::cin
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:146,
                 from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:113:5: error: 'vector' was not declared in this scope
  113 |     vector<int> a(n);
      |     ^~~~~~
a.cc:113:5: note: suggested alternatives:
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:428:11: note:   'std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/14/vector:93:13: note:   'std::pmr::vector'
   93 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
a.cc:113:12: error: expected primary-expression before 'int'
  113 |     vector<int> a(n);
      |            ^~~
a.cc:114:9: error: 'i' was not declared in this scope
  114 |     rep(i,n) cin >> a[i];
      |         ^
a.cc:114:5: error: 'rep' was not declared in this scope
  114 |     rep(i,n) cin >> a[i];
      |     ^~~
a.cc:115:5: error: 'map' was not declared in this scope
  115 |     map<int,int> mp;
      |     ^~~
a.cc:115:5: note: suggested alternatives:
In file included from /usr/include/c++/14/map:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152:
/usr/include/c++/14/bits/stl_map.h:102:11: note:   'std::map'
  102 |     class map
      |           ^~~
/usr/include/c++/14/map:89:13: note:   'std::pmr::map'
   89 |       using map
      |             ^~~
a.cc:115:9: error: expected primary-expression before 'int'
  115 |     map<int,int> mp;
      |         ^~~
a.cc:124:17: error: 'mp' was not declared in this scope; did you mean 'p'?
  124 |     for(auto p: mp){
      |                 ^~
      |                 p
a.cc:133:5: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
  133 |     cout << ans.x << endl;
      |     ^~~~
      |     std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:133:22: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
  133 |     cout << ans.x << endl;
      |                      ^~~~
      |                      std::endl
In file included from /usr/include/c++/14/istream:41,
                 from /usr/include/c++/14/sstream:40,
                 from /usr/include/c++/14/complex:45,
                 from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127:
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~