Problem:
Akabeko 20
Akabeko 20 is a group that performs at a dedicated theater in the Izua region. Each member of Akabeko 20 is supposed to participate in a performance every certain number of days.
Today's performance was attended by all the members. As a producer, you are asked by the members to tell the combination of the members for the upcoming performance. You decide to count the number of combinations of members participating in the performance.
Given the number of members of Akabeko 20 and the number of cycles that each member participates in the performance, write a program to count how many combinations of members to participate. Assume that the group will continue to exist forever with the same members. Note that if no one participates, it is not included in the combinations.
Input
The input is given in the following form.
$N$
$p_1$ $p_2$ ... $p_N$
In the first line, the number of members of Akabeko 20 $N$ ($1 \leq N\leq 20$) is given. In the following line, the period $p_i$ ($1 \leq p_i \leq 40$) that each member participates in the performance is given.
Output
Output the number of combinations of members participating in the performance on one line.
Sample Input and Output
Sample Input 1
3
3 5 2
Sample Output 1
7
Sample Input 2
3
2 3 6
Sample Output 2
3
There are three types of performances: one where only members with a cycle of 2 days participate, one where only members with a cycle of 3 days participate, and one where members with cycles of 2, 3, and 6 days participate.

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i)
#define all(a) (a).begin(),(a).end()

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    
    int N;
    cin >> N;
    vector<int> p(N);
    rep(i, 0, N) cin >> p[i];
    
    set<ll> S;
    rep(bit, 1, 1 << N) {
        ll L = 1;
        rep(i, 0, N) if ((bit >> i) & 1) L = lcm(L, p[i]);
        S.insert(L);
    }
    cout << S.size() << '\n';
}
accuracy: 1
time_ms: 440
memory_kb: 4340
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ld=long double;
#define fi first
#define se second
#define i128 __int128_t
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define si(a) (long)(a.size())
template<typename T>bool chmin(T&a,T b){return b<a?(a=b,1):0;}
template<typename T>bool chmax(T&a,T b){return b>a?(a=b,1):0;}
const int INF=1e9+100;
const long INFL=3e18+100;
struct _ {
   _() { cin.tie(0)->sync_with_stdio(0), cout.tie(0); }
} __;

int main(){
    int N;
    cin>>N;
    vector<int> P(N);
    rep(i,N)cin>>P[i];
    int ans=0;
    rep(b,1<<N){
        if(b==0) continue;
        unsigned long l=1;
        rep(i,N) if((b>>i)&1) l=l/gcd(l,P[i])*P[i];
        int h=0;
        rep(i,N) if(!((b>>i)&1)) if(l%P[i]==0) h=1;
        ans+=1-h;
    }
    cout<<ans<<"\n";
}
accuracy: 1
time_ms: 270
memory_kb: 3584
final_rank: 3

code_snippet: #include<bits/stdc++.h>
//#include<atcoder/all>

using namespace std;
//using namespace atcoder;
#define rep(i,n) for(ll i=0; i<n; i++)
#define rrep(i,n) for(ll i=n-1; i>=0; i--)
#define print(a) cout<<a<<endl
typedef long long ll;
#define yn(flg) if(flg){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YN(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define so(a) sort(a.begin(),a.end())
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define pb push_back
#define a2i(a,s) (ll)(a-s)
#define i2a(s,a) (char)(s+a)
#define ssize(a) a.size()
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<pair<ll,ll>,ll> P3;
typedef pair<pair<ll,ll>,pair<ll,ll>> P4;

typedef pair<ll, ll> Pll;
typedef pair<ll,Pll> Plll;
typedef pair<Pii, int> Piii;
const ll INF = 1000000000000000000;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll gcd(ll a, ll b){
  if(a%b == 0){
    return b;
  }else{
    return gcd(b, a%b);
  }
}

ll lcm(ll a, ll b){
  return a*b / gcd(a, b);
}
set<ll> saiki(ll bit,ll n){
	set<ll> s;
	for(ll i=0;i<n;i++){
		if(bit&(1<<i)){
			s.insert(i);
		}
	}
	return s;
}
vector<ll> b[20];

int main(){
//入力

	cin.tie(0);
	ios::sync_with_stdio(0);

	ll n;
	cin>>n;
	vector<ll> s(n);
	rep(i,n){
		cin>>s[i];
	}

//前計算
	ll ans=0;
//	rep(i,n){
//		rep(j,b[i].size()){
//			cout<<b[i][j]<<" ";
//		}
//		cout<<endl;
//	}
//判定
	for(ll bit=0;bit<(1<<n);bit++){
		set<ll> S=saiki(bit,n);
		if(S.size()==0)continue;
		bool v2=true;
		ll v=1;
		for(ll i:S){
			v=lcm(v,s[i]);
		}
		rep(i,n){
			if(S.find(i)!=S.end())continue;
			if(v%s[i]==0){
				v2=false;
				break;
			}
		}
		if(v2==true)ans++;
	}

	cout<<ans<<endl;

	return 0;
}
accuracy: 1
time_ms: 690
memory_kb: 3444
final_rank: 12

code_snippet: #include<bits/stdc++.h>

using namespace std;

#define rep(i, l, n) for(int i = int(l); i < int(n); i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

template<class T> bool chmin(T &a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T &a, T b) {if(a < b) {a = b; return true;} return false;}
template<class T> using spq = priority_queue<T, vector<T>, greater<T>>;

// bool -> Yes/No
string answer(bool b) {return b ? "Yes" : "No";}

void fix(int k) {cout << fixed << setprecision(k);}

const int inf = 2e9;
const long long INF = 2e18;
const long double eps = 1e-12;
int dx[] = {0, -1, 0, 1, -1, -1, 1, 1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

void main_program() {
    int n; cin >> n;
    ll x[n];
    rep(i, 0, n) cin >> x[i];
    int cnt = 0;
    rep(i, 1, 1 << n) {
        ll l = 1;
        rep(j, 0, n) {
            if(i & (1 << j)) {
                l = lcm(l, x[j]);
            }
        }
        bool ok = true;
        rep(j, 0, n) {
            if(i & (1 << j)) {
                continue;
            }
            if(l % x[j] == 0) ok = false;
        }
        if(ok) cnt++;
    }
    cout << cnt << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    //cin >> T;
    while(T--) {
        main_program();
    }
}
accuracy: 1
time_ms: 500
memory_kb: 3420
final_rank: 11

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(int i = 0;i<N;i++)
#define all(x) x.begin(),x.end()
#define fi first
#define se second
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
int main(){
    ll N;cin>>N;
    vector<ll>P(N);
    rep(i,N)cin>>P[i];
    int ans = 0;
    for(ll x = 1;x<(1<<N);x++){
        ll now = 1;
        rep(j,N){
            if((x&(1<<j))!=0){
                now/=gcd(now,P[j]);
                now*=P[j];
            }
        }
        bool can = true;
        rep(i,N){
            if((x&(1<<i))==0&&now%P[i]==0){
                can = false;
                break;
            }
        }
        if(can)ans++;
    }
    cout<<ans<<endl;
}
accuracy: 1
time_ms: 430
memory_kb: 3424
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ll long long
const long long mod=998244353;
const long long hmod=46216567629137;
ll gcd(ll a,ll b){
    while(true){
        if(a>b){
            a%=b;
        }
        else{
            b%=a;
        }
        if(a==0) return b;
        if(b==0) return a;
    }
}
vector<pair<int,int>>bunkai(int x){
    vector<pair<int,int>>res;
    for(int i=1;i*i<=x;i++){
        int c=0;
        while(x%i==0){
            x/=i;
            c++;
        }
        if(c>0) res.push_back({i,c});
    }
    if(x==1) return res;
    rep(i,res.size()){
        if(res[i].first==x){
            res[i].second++;
            return res;
        }
    }
    res.push_back({x,1});
    return res;
}
int main(){
    cin.tie(0)->sync_with_stdio(0);
    cout.tie(0);
    int N;
    cin>>N;
    ll p[N+1];
    for(int i=1;i<=N;i++) cin>>p[i];
    int ans=0;
    for(int i=1;i<(1<<N);i++){
        ll lcm=1;
        for(int j=1;j<=N;j++){
            if((i>>(j-1))&1){
                lcm=lcm*p[j]/gcd(lcm,p[j]);
            }
        }
        bool check=1;
        for(int j=1;j<=N;j++){
            if(!((i>>(j-1))&1)){
                if(lcm%p[j]==0) check=0;
            }
        }
        if(check) ans++;
    }
    cout<<ans<<endl;
}
accuracy: 1
time_ms: 490
memory_kb: 3368
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define oke cout << "Yes" << '\n';
#define dame cout << "No" << '\n';
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using HaiI = vector<vector<int>>;
using Hai2 = vector<vector<ll>>;
using HaiB = vector<vector<bool>>;
using Hai3 = vector<vector<vector<ll>>>;

ll gcd(ll m,ll n){
	if(m<n){
		swap(m,n);
	}
	while(n!=0){
		m%=n;
		swap(m,n);
	}
	return m;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(15);
	ll N;
	cin>>N;
	vector<ll>A(N);
	rep(i,N){
		cin>>A[i];
	}
	ll ans=0;
	for(int i=0;i<(1<<N);i++){
		ll g=-1;
		for(int d=0;d<N;d++){
			if(i & (1<<d)){
				if(g==-1){
					g=A[d];
				}else{
					g=g/gcd(A[d],g);
					g*=A[d];
				}
			}
		}
			int cut=0;
		bool ok=true;
		for(int d=0;d<N;d++){
			if(!(i & (1<<d))){
				if(g%A[d]==0){
					ok=false;
				}
				cut++;
			}
			if(cut==N){
				ok=false;
			}
		}
		if(ok){
			ans++;
		}
	}
	cout<<ans<<"\n";
}
accuracy: 1
time_ms: 470
memory_kb: 3432
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define oke cout << "Yes" << '\n';
#define dame cout << "No" << '\n';
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using HaiI = vector<vector<int>>;
using Hai2 = vector<vector<ll>>;
using HaiB = vector<vector<bool>>;
using Hai3 = vector<vector<vector<ll>>>;

int gcd(int m,int n){
	if(m<n){
		swap(m,n);
	}
	while(n!=0){
		m%=n;
		swap(m,n);
	}
	return m;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(15);
	ll N;
	cin>>N;
	vector<ll>A(N);
	rep(i,N){
		cin>>A[i];
	}
	ll ans=0;
	for(int i=0;i<(1<<N);i++){
		ll g=-1;
		for(int d=0;d<N;d++){
			if(i & (1<<d)){
				if(g==-1){
					g=A[d];
				}else{
					g=g*A[d]/gcd(A[d],g);
				}
			}
		}
			int cut=0;
		bool ok=true;
		for(int d=0;d<N;d++){
			if(!(i & (1<<d))){
				if(g%A[d]==0){
					ok=false;
				}
				cut++;
			}
			if(cut==N){
				ok=false;
			}
		}
		if(ok){
			ans++;
		}
	}
	cout<<ans<<"\n";
}
accuracy: 0.6363636363636364
time_ms: 410
memory_kb: 3432
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define ll int
#define INF 1<<30
vector<pair<ll,ll>> Prime_factorize(ll n){//素因数分解
    vector<pair<ll,ll>> res;
    for(ll i=2;i<=sqrt(n);i++){
        if(n%i==0){
            ll dvisor=i,ex=0;
            while(n%i==0){
                ex++;
                n/=i;
            }
            res.push_back({dvisor,ex});
        }
    }
    if(n!=1)res.push_back({n,1});
    return res;
}

int main(){

    ll n,ans=0;cin>>n;
    vector<ll> a(n);
    vector<map<ll,ll>> b(n);
    for(ll i=0;i<n;i++){
        cin>>a[i];
        vector<pair<ll,ll>> f=Prime_factorize(a[i]);
        for(auto& j:f)b[i][j.first]=j.second;
    }
    for(ll i=1;i<1<<n;i++){
        map<ll,ll> ma;
        for(ll j=0;j<n;j++){
            if(i&(1<<j)){
                for(auto& k:b[j]){
                    ma[k.first]=min(ma[k.first],-k.second);
                }
            }
        }
        bool ok=1;
        for(ll j=0;j<n;j++){
            if(!(i&(1<<j))){
                bool sub=0;
                for(auto& k:b[j]){
                    if(-ma[k.first]<k.second)sub=1;
                }
                if(!sub)ok=false;
            }
        }
        if(ok)ans++;
    }
    cout<<ans<<endl;
}
accuracy: 1
time_ms: 730
memory_kb: 3452
final_rank: 13

code_snippet: #include <bits/stdc++.h>
#include <iomanip>
#include <numbers>
#include <cassert>
#include <numeric>
#ifdef _MSC_VER
#include <intrin.h>
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pint = pair<int, int>;
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
template<typename T>
bool chmax(T & a, const T & b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T & a, const T & b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9;
const ll linf = 1e18;
const int dy[] = { 0,0,1,-1 }, dx[] = { 1,-1,0,0 };
int main() {
    int n; cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    set<ll> st;
    for (int bit = 1; bit < (1 << n); ++bit) {
        ll LCM = 1;
        rep(i, n) {
            if (bit & (1 << i))LCM = lcm(LCM, p[i]);
        }
        st.insert(LCM);
    }
    cout << st.size() << endl;
}
accuracy: 1
time_ms: 230
memory_kb: 4480
final_rank: 14

code_snippet: #include <bits/stdc++.h>
#include <iomanip>
#include <numbers>
#include <cassert>
#include <numeric>
#ifdef _MSC_VER
#include <intrin.h>
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pint = pair<int, int>;
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
template<typename T>
bool chmax(T & a, const T & b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T & a, const T & b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9;
const ll linf = 1e18;
const int dy[] = { 0,0,1,-1 }, dx[] = { 1,-1,0,0 };
int main() {
    int n; cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    set<int> st;
    for (int bit = 1; bit < (1 << n); ++bit) {
        int LCM = 1;
        rep(i, n) {
            if (bit & (1 << i))LCM = lcm(LCM, p[i]);
        }
        st.insert(LCM);
    }
    cout << st.size() << endl;
}
accuracy: 0.6363636363636364
time_ms: 200
memory_kb: 4480
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;

#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INF = 1e9 + 1;
const ll INFL = 1e18 + 1;
const double PI = 3.141592653589793238;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";

const vector<int> dx = {-1, 0, 1, 0};
const vector<int> dy = {0, 1, 0, -1};
const vector<int> dx8 = {-1, 0, 1, 0, -1, -1, 1, 1};
const vector<int> dy8 = {0, 1, 0, -1, -1, 1, 1, -1};
bool inRange(int i, int N) { return (0 <= i && i < N); }
bool inField(int i, int j, int H, int W) { return (0 <= i && i < H && 0 <= j && j < W); }
int encode(int i, int j, int W) { return (i * W + j); }

#define euclid(x1, y1, x2, y2) (((x1) - (x2)) * ((x1) - (x2)) + ((y1) - (y2)) * ((y1) - (y2)))
#define manhattan(x1, y1, x2, y2) (abs((x1) - (x2)) + abs((y1) - (y2)))

int randInt(int a, int b) { return a + rand() % (b - a + 1); }
double randDouble() { return 1.0 * rand() / RAND_MAX; }

int op(int a, int b) { return max(a, b); }
int e() { return -INF; }

#define rep(i, n) for(int i = 0;i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define chmin(a, b) a = min(a,b)
#define chmax(a, b) a = max(a,b)
#define sz(a) ((int) a.size())
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YN(a) cout << ((a) ? "Yes" : "No") << endl

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N;
    cin >> N;

    vector<int> P(N);
    for (int i = 0; i < N; i++) cin >> P[i];

    set<ll> st;
    for (int bit = 0; bit < (1 << N); bit++) {
        bool flag = false;
        ll A = 1;
        for (int i = 0; i < N; i++) {
            if ((bit >> i) & 1) {
                flag = true;
                A = lcm(A, P[i]);
            }
        }

        if (flag) st.emplace(A);
    }

    cout << st.size() << endl;
}
accuracy: 1
time_ms: 440
memory_kb: 4440
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef LOCAL
#include <debug_print.hpp>
#define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (static_cast<void>(0))
#endif

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N;
    cin >> N;
    vector<int> p(N);
    for (int i = 0; i < N; i++) cin >> p[i];

    // N 人のメンバーの組合せを bit 全探索
    int ans = 0;
    for (int bit = 1; bit < (1 << N); bit++) {
        // メンバーが bit のとき, 全員が参加する周期 L を求める
        ll L = 1;
        for (int i = 0; i < N; i++) {
            if ((bit >> i) & 1) L = lcm(L, p[i]);
        }
        // bit に含まれないメンバーが L 日の約数周期で参加するとき, bit の組合せは存在しない
        bool flag = true;
        for (int i = 0; i < N; i++) {
            if (!((bit >> i) & 1) && L % p[i] == 0) {
                flag = false;
            }
        }

        if (flag) ans++;
    }

    cout << ans << '\n';
}
accuracy: 1
time_ms: 260
memory_kb: 3584
final_rank: 2

code_snippet: #include <bits/stdc++.h>
#define asb(a,b) ((a)-(b)>0?(a)-(b):(b)-(a))
#define atio(v,n) for(int g=0;g<(n);++g)cin >> v[g]
#define atv(v) for(int g=0;g<((v).size());++g)cin >> v[g]
#define atdp(v,en) {int bbbbbb=0;for(auto o:v){if(bbbbbb)cout << en;bbbbbb=1;cout << o;}cout << endl;}
#define atfs(a) printf("%lld %lld\n",(a).first,(a).second)
#define ri(n) rp(i,n)
#define rj(n) rp(j,n)
#define rk(n) rp(k,n)
#define rl(n) rp(l,n)
#define rp(e,c) for(int e=0;e<(c);++e)
#define rix(s,h) rpx(i,s,h)
#define rjx(s,h) rpx(j,s,h)
#define rkx(s,h) rpx(k,s,h)
#define rlx(s,h) rpx(l,s,h)
#define rpx(e,s,h) for(int e=s;e<(h);++e)
#define ci(d,r) ((d)/(r)+(((d)%(r))!=0))
#define pn {pr("No");return 0;}
#define py {pr("Yes");return 0;}
#define pr(a) cout << (a) << endl
#define sbg(a) sort(bgen(a))
#define bgen(a) a.begin(),a.end()
#define INF 114514810
#define LNF 1ll<<60
#define upn(a,b) a=min(a,b)
#define upx(a,b) a=max(a,b)
#define asr(q,n) (0<=(q) && (q)<(n))
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using si=set<int>;
using sll=set<ll>;
using qi=queue<int>;
using qll=queue<ll>;
using qpii=queue<pii>;
using qpll=queue<pll>;
using vst=vector<string>;
using vsi=vector<si>;
using vvi=vector<vi>;
using vvl=vector<vll>;
using tiii=tuple<int,int,int>;
using tlll=tuple<ll,ll,ll>;
using mii=map<int,int>;
using mll=map<ll,ll>;
using stki=stack<int>;
using stkll=stack<ll>;
using tiis=tuple<int,int,string>;
using pdf=pair<pair<int,long double>,pii>;
int dx[4]={1,0,-1,0};
int dy[4]={0,-1,0,1};

template <typename T,class Fn>
struct sgt{ // 1-indexed
  vector<T> seg;
  int n;
  T d;
  Fn f;
  sgt(vector<T>& n2,T d,Fn f) : n(n2.size()),d(d), f(f){
    int b=n;
    while(!(b&1))b>>=1;
    if(b!=1){
      int c=0;
      b=n;
      while(b){b>>=1;++c;}
      n=1<<c;
    }
    seg=vector<T>(n<<1,d);
    b=n2.size();
    ri(b)seg[n+i]=n2[i];
    b=n;
    while(b>1){
      for(int i=b/2;i<b;++i)seg[i]=f(seg[2*i],seg[2*i+1]);
      b/=2;
    }
	return;
  }
  void update(int pos,T val){
    int i=n+pos;
    seg[i]=val;
    while(i/=2)seg[i]=f(seg[2*i],seg[2*i+1]);
	return;
  }
  T get(int l,int r){
    T tmp=d;
    int p=l;
    int c=0;
    while((p+(1<<c))<=r){
      if(p&(1<<c)){
        tmp=f(tmp,seg[(p>>c)+(n>>c)]);
        p+=1<<c;
      }
      ++c;
    }
    --c;
    while(p<r){
      if((r-p)&(1<<c)){
        tmp=f(tmp,seg[(p>>c)+(n>>c)]);
        p+=(1<<c);
      }
      --c;
    }
    return tmp;
  }
  T get(int pos){
    return seg[n+pos];
  }
};

ll gcd(ll a,ll b){
  if(a==0 || b==0)return 1;
  while(a%=b)swap(a,b);
  return b;
}

int main(){
  int n;
  cin >> n;
  vi p(n);
  atv(p);
  sort(bgen(p),greater<int>());
  int ans=0;
  ri(1<<n){
    if(!i)continue;
    si s;
    bool f=true;
    ll lcm=1;
    rj(n){
      if((1<<j)&i){
        s.insert(p[j]);
        lcm/=gcd(p[j],lcm);
        lcm*=p[j];
      }else{
        for(int x:s)if(x%p[j]==0){
          f=false;
          break;
        }
      }
    }
    if(f){
      rj(n){
        if(!((1<<j)&i)){
          if(lcm%p[j]==0){
            f=false;
            break;
          }
        }
      }
    }
    if(f){
      ++ans;
    }
  }
  pr(ans);
}
accuracy: 1
time_ms: 880
memory_kb: 3488
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(T) T.begin(), T.end()
using ll = long long;
using P = pair<int, int>;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};

int main() {
    ll n;
    cin >> n;
    vector<ll> v(n);
    rep(i, n) cin >> v[i];
    sort(all(v));
    ll ans = 0;
    for (int bit = 1; bit < (1 << n); bit++) {
        bool ok = true;
        ll L = 1;
        rep(i, n) if ((bit >> i) & 1) L = lcm(L, v[i]);
        rep(i, n) if (!((bit >> i) & 1)) if (L % v[i] == 0) ok = false;
        if (ok) {
            // rep(i, n) cout << ((bit >> i) & 1) << endl;
            ans++;
        }
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 270
memory_kb: 3584
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...)
#endif

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N;
    cin >> N;
    vector<ll> p(N);
    for (int i = 0; i < N; i++) cin >> p[i];

    int ans = 0;
    for (int bit = 1; bit < (1 << N); bit++) {
        ll L = 1;
        for (int i = 0; i < N; i++) {
            if ((bit >> i) & 1) L = lcm(L, p[i]);
        }
        // bit に含まれないメンバーの周期が L の約数の場合, 不可能
        bool ok = true;
        for (int i = 0; i < N; i++) {
            if ((bit >> i) & 1) continue;
            if (L % p[i] == 0) ok = false;
        }
        if (ok) ans++;
    }

    cout << ans << '\n';
}
accuracy: 1
time_ms: 280
memory_kb: 3584
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;

template <typename T>
using vc = vector<T>;
template <typename T>
using vv = vc<vc<T>>;

//-------------1.型系---------------
using ll = long long;
ll INF = 2e18;

using ld = long double;
using bl = bool;
using mint = modint998244353;
// using mint = modint1000000007;
//   using mint = modint;
//   mint::set_mod(m);

template <class T>
using pq = priority_queue<T, vc<T>>;
template <class T>
using pq_g = priority_queue<T, vc<T>, greater<T>>;
//-----------------------------------

//-------------2.配列系--------------

using pii = pair<int, int>;
using pll = pair<long long, long long>;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
template <class T>
istream &operator>>(istream &i, vc<T> &v)
{
    rep(j, size(v)) i >> v[j];
    return i;
}

using ar2 = array<ll, 2>;

//----------------------------------

//--------3.コード短縮化とか---------
const double PI = 3.141592653589793238;
const int inf = 1073741823;
const ll infl = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define drep(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define nfor(i, s, n) for (ll i = s; i < n; i++)
#define dfor(i, s, n) for (ll i = (s) - 1; i >= n; i--)

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YN                     \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    } // if(a==b)YN;

#define vc_unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define vc_rotate(v) rotate(v.begin(), v.begin() + 1, v.end());

#define pop_cnt(s) ll(popcount(uint64_t(s)))

#define next_p(v) next_permutation(v.begin(), v.end())

//-------------------------------

//---------4.グリッド系----------
vector<int> dx = {1, 0, -1, 0}; //  dx={1,1,0,-1,-1,-1,0,1};
vector<int> dy = {0, 1, 0, -1}; //  dy={0,1,1,1,0,-1,-1,-1};

bool out_grid(ll i, ll j, ll h, ll w = -1)
{
    if (w == -1)
    {
        w = h;
    }
    return (!(0 <= i && i < h && 0 <= j && j < w));
}

#define vvl_rotate(v)                                   \
    {                                                   \
        ll n = size(v);                                 \
        vvl nx(n, vl(n));                               \
        rep(i, n) rep(j, n) nx[j][n - i - 1] = v[i][j]; \
        swap(nx, v);                                    \
    } // 時計回りに90°回転
// #define vvl_rotate(v) {ll n = size(v);vvl
// nx(n,vl(n));rep(i,n)rep(j,n)nx[n-j-1][i]=v[i][j];swap(nx,v);}//反時計周りに90°回転

#define vs_rotate(v)                                    \
    {                                                   \
        ll n = size(v);                                 \
        vs nx(n, string(n, '.'));                       \
        rep(i, n) rep(j, n) nx[j][n - i - 1] = v[i][j]; \
        swap(nx, v);                                    \
    } // 文字列版 時計回りに90°回転
// #define vs_rotate(v) {ll n = size(v);vs
// nx(n,string(n,'.'));rep(i,n)rep(j,n)nx[n-j-1][i]=v[i][j];swap(nx,v);}//文字列版　反時計周りに90°回転

#define vvl_transpos(v)                         \
    {                                           \
        ll n = size(v);                         \
        vvl nx(n, vl(n));                       \
        rep(i, n) rep(j, n) nx[j][i] = v[i][j]; \
        swap(nx, v);                            \
    }
#define vs_transpos(v)                          \
    {                                           \
        ll n = size(v);                         \
        vs nx(n, string(n, '.'));               \
        rep(i, n) rep(j, n) nx[j][i] = v[i][j]; \
        swap(nx, v);                            \
    }

//--------------------------------

//-----------5.数学系--------------
#define euclid(x, y) ((x) * (x) + (y) * (y)) // ユークリッド距離 2乗のまま
#define manhattan(x1, x2, y1, y2) \
    (abs(x1 - x2) + abs(y1 - y2)) // マンハッタン距離 = |x1-x2|+|y1-y2|

template <class T>
T tousa_sum1(T l, T d, T r)
{ // 初項,公差,末項 で総和を求める
    T wide = (r - l) / d + 1;
    return (l + r) * wide / 2;
}
template <class T>
T tousa_sum2(T a, T d, T n)
{ // 初項,交差,項数 で総和を求める
    return (a * 2 + d * (n - 1)) * n / 2;
}
ll kousa_kousuu(ll l, ll r, ll d)
{ // 初項,末項,交差 で等差数列の項数を求める
    return (r - l) / d + 1;
}
mint touhi_sum(mint a, mint r,
               ll n)
{ // 初項,公比,項数で等比数列の総和を求める
    if (r == 1)
    {
        return a * n;
    }
    mint bunsi = a * (r.pow(n) - mint(1));
    mint bunbo = r - 1;
    return bunsi / bunbo;
}

ll nc2(ll x) { return x * (x - 1) / 2; }
ll nc3(ll x) { return x * (x - 1) * (x - 2) / 6; }

//----------------------------------------------

//-----------6.デバックや出力系------------------
void print(ld x) { printf("%.20Lf\n", x); }

#define print_vec(v)                   \
    {                                  \
        ll n = size(v);                \
        rep(i, n) cout << v[i] << " "; \
        cout << endl;                  \
    } // 一次元配列を出力する(改行なし)

#define vc_cout(v)                      \
    {                                   \
        ll n = size(v);                 \
        rep(i, n) cout << v[i] << endl; \
    } // 一次元配列を出力する(改行あり)
#define vv_cout(v)                                         \
    {                                                      \
        ll n = size(v);                                    \
        rep(i, n)                                          \
        {                                                  \
            rep(j, size(v[i])) { cout << v[i][j] << ' '; } \
            cout << endl;                                  \
        }                                                  \
    } // 二次元配列を出力する
//----------------------------------------------

int main()
{
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<ll> p(n);
    cin >> p;
    int ans = 0;
    rep(bit, 1 << n)
    {
        ll v = 1;
        rep(i, n) if (bit & 1 << i) v = lcm(v, p[i]);

        if (pop_cnt(bit) == 0)
            continue;
        bool f = true;
        rep(i, n)
        {
            if (!(bit & 1 << i))
            {
                if (v % p[i] == 0)
                    f = false;
            }
        }
        if (f)
            ans++;
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 250
memory_kb: 3584
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int N; cin >> N;
    vector<int> p(N);
    for(int i = 0; i < N; i++) cin >> p[i];
    
    set<long long> st;
    
    for(int bit = 1; bit < (1 << N); bit++){
        long long s = 1;
        for(int i = 0; i < N; i++){
            if(bit >> i & 1) s = lcm(s, p[i]);
        }
        
        st.insert(s);
    }
    
    
    cout << st.size() << endl;
    
}
accuracy: 1
time_ms: 430
memory_kb: 4160
final_rank: 15

code_snippet: #include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return ((a * b) / g);
}
int main() {
	int N;cin >> N;
	vector<ll> P(N);
	int ans = 0;
	for (int i = 0;i < N;i++) cin >> P[i];
	for (int bit = 1;bit < (1 << N);bit++) {
		ll L = 1;
		for (int i = 0;i < N;i++) {
			if (bit & (1 << i)) L = lcm(L, P[i]);
		}
		bool ret = true;
		for (int i = 0;i < N;i++) {
			if (!(bit & (1 << i))) {
				if (L % P[i] == 0) ret = false;
			}
		}
		if (ret) ans++;
	}
	cout << ans << endl;
}
accuracy: 1
time_ms: 490
memory_kb: 3428
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vs = vector<string>;
using pii = pair<int, int>;
template<class T> istream &operator>>(istream &is, vector<T> &v) {for (auto &x : v){is >> x;} return is;}
#define pb emplace_back
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b; return true;} return false;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b; return true;} return false;}

int main() {
    int N; cin >> N;
    vll P(N); cin >> P;
    sort(all(P));
    int ans = 0;
    for (int bits = 1; bits < (1<<N); bits++) {
        ll x = 1;
        for (int i = 0; i < N; i++) {
            if (bits&(1<<i)) x = lcm(x, P[i]);
        }
        bool flag = true;
        for (int i = 0; i < N; i++) {
            if (!(bits&(1<<i)) && x%P[i]==0) flag = false;
        }
        if (flag) ans++;
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 490
memory_kb: 3424
final_rank: 9