Language: C++

#include <vector>
#include <map>
#include <numeric>
#include <iostream>
#include <cmath>

using prime_map = std::map<int, int>;

const int MAX_A = 1000000;
const uint_fast64_t MOD = 1000000007;


prime_map prime_list;


template<class T, class Key>
T::mapped_type at_or_defaulut(const T &c, Key key)
{
    auto i = c.find(key);
    if( i != c.end() )
    {
        return Key();
    }
    else
    {
        return i->second;
    }
}

prime_map listPrimes(int N)
{
    int sqrN = static_cast<int>(std::sqrt(N));
    prime_map P;
    
    for(int i = 2; i <= sqrN; ++i)
    {
        P[i] = 0;
    }
    
    for(int i = 2; i <= sqrN; ++i)
    {
        if(P[i] == 0)
        {
            for(int j = i * 2; j <= sqrN; j += i)
            {
                ++P[j];
            }
        }
    }
    
    prime_map PP;
    for(auto p : P)
    {
        if(p.second == 0)
        {
            PP.insert(p);
        }
    }
    
    prime_list = PP;
    return PP;
}

prime_map factorise(int M)
{
    prime_map P = prime_list;
    
    int mm = M;
    for(auto &p : P)
    {
        while(mm % p.first == 0)
        {
            ++p.second;
            mm = mm / p.first;
        }
    }
    
    if(mm) P[mm] = 1;
    
    return P;
}

void prime_map_max(prime_map &PMax, const prime_map &P)
{
    for(auto &p : PMax)
    {
        if(p.second < at_or_defaulut(P, p.first))
        {
            p.second = P.at(p.first);
        }
    }
}

uint_fast64_t prime_map_diff(const prime_map &P1, const prime_map &P2)
{
    uint_fast64_t b = 1;
    for(auto p : P1)
    {
        int diff = p.second - at_or_defaulut(P2, p.first);
        for(int j = 0; j < diff; ++j)
        {
            b *= p.first;
        }
    }
    return b;
}

int main()
{
    int M;
    std::cin >> M;
    
    std::vector<int> A(M);
    for(int i = 0; i < M; ++i)
    {
        std::cin >> A[i];
    }
    
    listPrimes(MAX_A);
    
    std::vector<prime_map> PA(M);
    prime_map PMax = prime_list;
    for(int i = 0; i < M; ++i)
    {
        PA[i] = factorise(A[i]);
        prime_map_max(PMax, PA[i]);
    }
    
    
    uint_fast64_t BSum = 0;
    for(int i = 0; i < M; ++i)
    {
        uint_fast64_t b = prime_map_diff(PMax, PA[i]);
        BSum = (BSum + b) % MOD;
    }
    std::cout << BSum << std::endl;
}

Compiler output:
a.cc:10:7: error: 'uint_fast64_t' does not name a type
   10 | const uint_fast64_t MOD = 1000000007;
      |       ^~~~~~~~~~~~~
a.cc:17:1: error: need 'typename' before 'T::mapped_type' because 'T' is a dependent scope
   17 | T::mapped_type at_or_defaulut(const T &c, Key key)
      | ^
      | typename 
a.cc: In function 'void prime_map_max(prime_map&, const prime_map&)':
a.cc:87:23: error: 'at_or_defaulut' was not declared in this scope
   87 |         if(p.second < at_or_defaulut(P, p.first))
      |                       ^~~~~~~~~~~~~~
a.cc: At global scope:
a.cc:94:1: error: 'uint_fast64_t' does not name a type
   94 | uint_fast64_t prime_map_diff(const prime_map &P1, const prime_map &P2)
      | ^~~~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:130:5: error: 'uint_fast64_t' was not declared in this scope
  130 |     uint_fast64_t BSum = 0;
      |     ^~~~~~~~~~~~~
a.cc:133:22: error: expected ';' before 'b'
  133 |         uint_fast64_t b = prime_map_diff(PMax, PA[i]);
      |                      ^~
      |                      ;
a.cc:134:9: error: 'BSum' was not declared in this scope
  134 |         BSum = (BSum + b) % MOD;
      |         ^~~~
a.cc:134:24: error: 'b' was not declared in this scope
  134 |         BSum = (BSum + b) % MOD;
      |                        ^
a.cc:134:29: error: 'MOD' was not declared in this scope
  134 |         BSum = (BSum + b) % MOD;
      |                             ^~~
a.cc:136:18: error: 'BSum' was not declared in this scope
  136 |     std::cout << BSum << std::endl;
      |                  ^~~~