Cod sursa(job #3129800)

Utilizator PVDoriginalPopescu Vladut Daniel PVDoriginal Data 15 mai 2023 20:58:54
Problema Indep Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.3 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<int>> dp(n+1, vector<int>(1001, 0));

        int _max = 0;

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

            fin >> x; _max = max(_max, x);
            for(int j = 2; j <= x; ++j){
                //cout << j << " ";
                if(__gcd(x, j) != 1)
                    dp[i+1][j] = dp[i][j] + 1;//, cout << "added! ";
                else
                    dp[i+1][j] = dp[i][j];
            }
            for(int j = x+1; j <= _max; ++j)
                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;
    }