/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 5ms 532.0 KiB
#3 Accepted 24ms 564.0 KiB
#4 Accepted 20ms 532.0 KiB
#5 Accepted 17ms 320.0 KiB
#6 Accepted 18ms 532.0 KiB
#7 Accepted 13ms 532.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pii pair<int,int>
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int MOD = 1000000007;
const int INF = 1e18;
const int N = 2e5;
int gcd(int a,int b){

    if(b==0)return a;

    return gcd(b,a%b);
}
void solve(int tc){
    int n; cin >> n;
    vector<int>v(n);
    for(int i=0;i<n;i++)
        cin >> v[i];
    vector<int>g(n+1);
    for(int i=1;i<(1ll<<n);i++){
        int sz = __builtin_popcount(i) , gc = 0;
        for(int j=0;j<n;j++){
            if(i >> j & 1){
                gc= gcd(gc,v[j]);
            }
        }
        g[sz] = (g[sz] + gc) % MOD;
    }
    int ans = 1;
    for(int i=1;i<=n;i++)ans = (ans * g[i]) % MOD;
    cout << ans << endl;
}
int32_t main(){
    Fast
    int t=1;
    cin >> t;
    for(int tc=1;tc<=t;tc++)
        solve(tc);
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1105 Ohh that gcd again
Contest
LUCC Presents Intra LU Junior Programming Contest - Replay
Language
C++17 (G++ 13.2.0)
Submit At
2025-09-02 16:45:28
Judged At
2025-09-02 16:45:28
Judged By
Score
100
Total Time
24ms
Peak Memory
564.0 KiB