Cod sursa(job #3129801)

Utilizator PVDoriginalPopescu Vladut Daniel PVDoriginal Data 15 mai 2023 21:00:22
Problema Indep Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.2 kb
#include<bits/stdc++.h>
using namespace std;

    #define ll long long

    ifstream fin("indep.in");
    ofstream fout("indep.out");

    int main(){

        //ios_base::sync_with_stdio(false);
        //cin.tie(NULL);

        int n; fin >> n;

        vector<bool> isPrime(1001, true);

        for(int i = 2; i <= 1000; ++i){
            if(!isPrime[i]) continue;
            for(int j = 2; i*j <= 1000; ++j)
                isPrime[i*j] = false;
        }

        vector<vector<ll>> dp(n+1, vector<ll>(1001, 0));

        int _max = 0;

        for(int i = 0, x; i < n; ++i){

            fin >> x; _max = max(_max, x);
            for(int j = 2; j <= 1000; ++j){

                if(!isPrime[j]) continue;

                if(__gcd(x, j) != 1)
                    dp[i+1][j] = dp[i][j] + 1;
                else
                    dp[i+1][j] = dp[i][j];
            }
        }

        //for(int i = 2; i <= 6; ++i)
        //    cout << i << ": " << dp[n][i] << "\n";

        ll total = (1LL << (1LL*n)) - n - 1;

        for(int i = 2; i < 1000; ++i)
            if(isPrime[i])
                total -= (1LL << dp[n][i]) - dp[n][i] - 1;

        fout << total;
    }