Cod sursa(job #3152794)

Utilizator db_123Balaban David db_123 Data 26 septembrie 2023 20:09:26
Problema Indep Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 4.77 kb
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

ifstream cin("indep.in");
ofstream cout("indep.out");

class BigInt {
    private:
    std::vector <int > v;
    const static int  base = 100000000;

    void normalize() {
        for(int i = 0; i < v.size(); i ++) {
            if(v[i] < 0) {
                v[i+1] --;
                v[i] += base;
            }
            else if(v[i] >= base) {
                if(i == v.size() - 1)
                    v.push_back(0);
                v[i+1] += v[i] / base;
                v[i] %= base;
            }
        }
        while(v.size() > 1 and v.back() == 0)
            v.pop_back();
    }
    public:

    BigInt() {};

    BigInt(int  value) {
        while(value) {
            v.push_back(value % base);
            value /= base;
        }
    }

    BigInt(std::string &s) {
        long long  value = 0, p = 1;
        for(int i = s.size()-1; i >= 0; i --) {
            value = value + p * (s[i] - '0');
            p *= 10;
            if(p >= base) {
                v.push_back(value);
                value = 0;
                p = 1;
            }
        }
        if(value > 0)
            v.push_back(value);
    }

    friend std::ofstream& operator << (std::ofstream &out, const BigInt &value) {
        for(int i = value.v.size() - 1; i >= 0; i --) {
            if(i != value.v.size() - 1){
                int aux = value.v[i];
                while(aux * 10 < base) {
                    aux *= 10;
                    out << '0';
                }
                    
            }
            out << value.v[i];
        }
        return out;
    }

    BigInt operator +(const BigInt &other) {
        BigInt ans;
        for(int i = 0; i < std::max(v.size(), other.v.size()); i ++) {
            int  value = 0;
            if(i < v.size())
                value += v[i];
            if(i < other.v.size())
                value += other.v[i];
            ans.v.push_back(value);
        }

        ans.normalize();
        return ans;
    }

    BigInt operator +(const int  &other) {
        BigInt ans;
        for(int i = 0; i < v.size(); i ++)
            ans.v.push_back(v[i]);
        ans.v[0] += other;
        ans.normalize();
        return ans;
    }

    BigInt operator -(const BigInt &other) {
        BigInt ans;
        for(int i = 0; i < std::max(v.size(), other.v.size()); i ++) {
            int  value = 0;
            if(i < v.size())
                value += v[i];
            if(i < other.v.size())
                value -= other.v[i];
            ans.v.push_back(value);
        }

        ans.normalize();
        return ans;
    }

    BigInt operator /(const int &other) {
        BigInt ans;
        long long  remainder = 0;
        for(int i = v.size() - 1; i >= 0; i --) {
            ans.v.push_back((remainder + v[i]) / other);
            remainder = (remainder + v[i]) % other;
            remainder *= base;
        }
        std::reverse(ans.v.begin(), ans.v.end());
        while(ans.v.size() > 1 and ans.v.back() == 0)
            ans.v.pop_back();
        return ans;
    }

    int modulus(const int  &div) {
        long long  remainder = 0;
        for(int i = v.size() - 1; i >= 0; i --) {
            remainder = (remainder + v[i]) % div;
            remainder *= base;
        }
        return remainder;
    }

    bool operator <( const BigInt& other) const {
        if(v.size() != other.v.size())
            return v.size() < other.v.size();
        for(int i = v.size() - 1; i >= 0; i --) {
            if(v[i] != other.v[i])
                return v[i] < other.v[i];
        }
        return true;
    }

};

const int DIM = 1e3;

int n;
vector<int> v,primes;
bool* sieve;
vector<int> mb(DIM+1,1);

void read() {
    cin>>n;
    v.resize(n+1);
    for(int i=1;i<=n;i++) {
        cin>>v[i];
    }
}

void constructPrimes() {
    sieve = new bool[DIM+1];
    sieve[1]=1;
    for(int i=2;i*i<=n;i++) {
        if(sieve[i]) {
            continue;
        }
        primes.push_back(i);
        for(int j=i*i;j<=DIM;j+=i) {
            sieve[j]=1;
        }
    }
}

void build_mb() {
    int sq = sqrt(DIM);
    for(int i=1;i<=DIM;i++) {
        if(sieve[i]) {
            continue;
        }
        for(int j=i;j<=DIM;j+=i) {
            mb[j]*=-1;
        }
        if(i>=sq) {
            continue;
        }
        for(int j=i*i;j<=DIM;j+=i*i) {
            mb[j]=0;
        }
    }
}

void solve() {
    constructPrimes();

    vector<int> fr_mult(1e3+1);
    for(int x=1;x<=1e3;x++) {
        for(int i=1;i<=n;i++) {
            if(v[i]%x==0) {
                fr_mult[x]++;
            }
        }
    }

    build_mb();

    BigInt rs=0;
    for(int x=1;x<=1e3;x++) {
        rs = rs + mb[x] * ( (1<<fr_mult[x])-1);
    }
    cout<<rs;
}

int32_t main() {

    read();
    solve();
    return 0;
}