/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 6ms 320.0 KiB
#3 Accepted 24ms 532.0 KiB
#4 Accepted 21ms 536.0 KiB
#5 Accepted 18ms 532.0 KiB
#6 Accepted 17ms 532.0 KiB
#7 Accepted 12ms 532.0 KiB

Code

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
using std::mt19937_64;
using std::random_device;
using std::uniform_int_distribution;
#include <numeric>
#define ff              first
#define ss              second
#define int              long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
void cpc()
{
#ifndef ONLINE_JUDGE
    freopen("guard.in", "r", stdin);
    freopen("guard.out", "w", stdout);
#endif
}
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int exp(int x, int n, int m) {
    if(x == 0 and n == 0) return 1;
    x %= m; 
    int res = 1;
    while (n > 0) {
        if (n % 2 == 1) { res = res * x % m; }
        x = x * x % m;
        n /= 2;
    }
    return res;
}
int gcd(int a,int b){
    if(a == 0) return b;
    return gcd(b%a,a);
}
struct cow{
int he,we,str;
};
 
signed main()
{  
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cpc();
    int t=1;
    cin >> t;
    while(t--){
    int n;
    cin >> n;
    vector<int> v(n);
    for(auto &x:v) cin >> x;
    int ans = 1;
    vector<int> ct(n+1,0);
    for(int i = 1; i < (1<<n); i++){
      int gc = 0;
      for(int j = 0 ; j < n; j++){
        if(i&(1<<j)){
            gc = __gcd(gc,v[j]);
        }
      }
      int x = __builtin_popcountll(i);
      ct[x] += gc;
    }
    for(int i = 1; i <= n; i++){
        ans = (ans*ct[i])%mod;
    }
    cout<<ans<<endl;


    }
    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:51:45
Judged At
2025-09-02 15:51:45
Judged By
Score
100
Total Time
24ms
Peak Memory
536.0 KiB