/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 536.0 KiB
#2 Accepted 14ms 532.0 KiB
#3 Accepted 45ms 532.0 KiB
#4 Accepted 23ms 532.0 KiB
#5 Accepted 20ms 532.0 KiB
#6 Accepted 19ms 532.0 KiB
#7 Accepted 12ms 560.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
#define optimize()                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);cout.tie(NULL);
#define fraction()                \
    cout.unsetf(ios::floatfield); \
    cout.precision(20);           \
    cout.setf(ios::fixed, ios::floatfield);
#define file()                        \
    freopen("input.txt", "r", stdin); \
    freopen("output", "w", stdout);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pr;
template <typename T> using ordered_set = tree <T, null_type,less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll lcm(ll a, ll b)
{
    return (a * b) / __gcd(a, b);
}
int gcd(ll a, ll b)
{
    return __gcd(a, b);
}
#define el "\n"
const int mod = 1e9+7;
const int mx = 5e5 + 125;

bool com(const pair<ll, ll> &p1, const pair<ll, ll> &p2)
{
    if (p1.first == p2.first) return p1.second > p2.second;
    return p1.first < p2.first;
}
bool compare(const pair<pair<int, int>, int>& a, const pair<pair<int, int>, int>& b)
{

    if (a.first.first != b.first.first)
        return a.first.first < b.first.first;
    if (a.first.second != b.first.second)
        return a.first.second < b.first.second;
    return a.second < b.second;
}

//const int mx = 1e8;
bitset<mx> isPrime;
vector<int> primes;
map<int,int>m;

void primeGen ( int n )
{
    for ( int i = 3; i <= n; i += 2 ) isPrime[i] = 1;

    int sq = sqrt(n);
    for ( int i = 3; i <= sq; i += 2 )
    {
        if(isPrime[i])
        {
            for ( int j = i*i; j <= n; j += i )
            {
                isPrime[j] = 0;
            }
        }
    }

    primes.push_back(2);

    for ( int i = 3; i <= n; i += 2 )
    {
        if(isPrime[i] == 1)
        {
            primes.push_back(i);
        }
    }
}

void factors(int x)
{
    for ( auto p : primes )
    {
        for ( int i = p; i <= primes.size(); i += p )
        {
            int n = x;

            while ( n % p == 0 )
            {
                //factors[i].push_back(p);
                m[p]++;
                n /= p;
            }
        }
    }

}

int power(ll x,ll y)
{
    int num=1;
    for(int i=0; i<y; i++)
    {
        num*=3;
    }
    return num;
}




void giveanswer()
{
    ll n,i,j;
    cin>>n;
    vector<ll>a(n);
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    ll ans=1;
    vector<ll>v;
    map<ll,ll>m;
    for ( i = 0; i < (1 << n); ++i) {
        v.clear();
        for (j = 0; j < n; ++j) {
            // Check if the j-th bit of i is set
            if ((i & (1 << j)) != 0) {
               //cout << a[j] << " ";
               v.push_back(a[j]);
            }
        }
        //cout<<el;
        if(v.size()==0)continue;
        ll gd=v[0];
        for(int l=1;l<v.size();l++)
        {
            gd=__gcd(gd,v[l]);
        }
        ll x=m[v.size()];
        m[v.size()]=(x+gd);


    }
    for(auto u:m)
    {
        ans=(ans*u.second)%mod;
    }
    cout<<ans<<el;
}

int main()
{
    optimize();
    fraction();
    int t;
    cin>>t;
    while(t--)
    {
    giveanswer();
    }
}


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:43:25
Judged At
2025-09-02 16:43:25
Judged By
Score
100
Total Time
45ms
Peak Memory
560.0 KiB