/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 3ms 532.0 KiB
#3 Accepted 16ms 532.0 KiB
#4 Accepted 15ms 532.0 KiB
#5 Accepted 11ms 532.0 KiB
#6 Accepted 9ms 532.0 KiB
#7 Accepted 8ms 532.0 KiB

Code

// @rakibul-islam

#include "bits/stdc++.h"
using namespace std;

using ll = long long;
const ll oo = 1e17;
const ll mod = 1e9 + 7;

void solve() {
  int n;  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  ll res = 1;
  ll sz[n + 1]{};
  for (int msk = 1; msk < (1 << n); msk++) {
    ll gd = 0;
    int s = 0;
    for (int i = 0; i < n; i++) if (msk & (1 << i)) {
      gd = gcd(gd, a[i]);
      s++;
    }
    sz[s] += gd;
    sz[s] %= mod;
  }
  for (int i = 1; i <= n; i++) {
    res *= sz[i];
    res %= mod;
  }
  cout << res << "\n";
} 

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int t = 1;  cin >> t;
  for (int test = 1; test <= t; test++) {
    solve();
  }
  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 15:49:13
Judged At
2025-09-02 15:49:13
Judged By
Score
100
Total Time
16ms
Peak Memory
532.0 KiB