0w1

CFR 615 D. Multipliers ( Math )

Problem - D - Codeforces
The number that some prime would be involved in the multiplication, is the cumulative product of the count of power for all other primes, again multiplied by ( 1 + 2 + .. + c ), where c is the count of power of the prime itself. And since a^( p - 1 ) = 1 ( mod p ), by little Fermat's, we can deduce that a^x % p = a^( x % ( p - 1 ) ).

const int MAXM = 2e5 + 5;
const int MAXP = 2e5 + 5;
const int MOD = 1e9 + 7;

int int_pow( int x, int p, int mod ){
    int res = 1;
    while( p ){
        if( p & 1 ) res = 1LL * res * x % mod;
        p >>= 1;
        x = 1LL * x * x % mod;
    }
    return res;
}

int M;
int P[ MAXM ];

void solve(){
    cin >> M;
    for( int i = 0; i < M; ++i )
        cin >> P[ i ];

    map< int, int > p_freq;
    for( int i = 0; i < M; ++i )
        ++p_freq[ P[ i ] ];

    int ans = 1, cnt = 1;
    for( auto it = p_freq.begin(); it != p_freq.end(); ++it ){
        ans = int_pow( ans, it->second + 1, MOD );
        int v = int_pow( it->first, 1LL * it->second * ( it->second + 1 ) / 2 % ( MOD - 1 ), MOD );
        v = int_pow( v, cnt, MOD );
        ans = 1LL * ans * v % MOD;
        cnt = 1LL * cnt * ( it->second + 1 ) % ( MOD - 1 );
    }

    cout << ans << "\n";
}