Cod sursa(job #1713544)

Utilizator killer301Ioan Andrei Nicolae killer301 Data 5 iunie 2016 21:21:49
Problema Indep Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 3.2 kb
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>

using namespace std;

const int NMAX = 500;
const int CIFMAX = 300;

int a[NMAX+5];
int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 27, 29, 31, 37, 41};

class HN
{
private:
    int n;
    int a[CIFMAX];
public:
    HN()
    {
        n = 1;
        memset(a, 0, sizeof(a));
    }
    HN(int x)
    {
        n = 0;
        memset(a, 0, sizeof(a));
        do
        {
            a[n++] = x%10;
            x/=10;
        }
        while(x);
    }
    HN &operator + (const HN &other)
    {
        HN ans;
        ans.n = max(n, other.n);
        int c = 0;
        for(int i=0; i<ans.n; i++)
        {
            ans.a[i] = a[i]+other.a[i]+c;
            c = ans.a[i]/10;
            ans.a[i]%=10;
        }
        if(c) ans.a[ans.n++] = c;
        return ans;
    }
    HN &operator - (const HN &other)
    {
        HN ans;
        ans.n = n;
        int c = 0;
        for(int i=0; i<n; i++)
        {
            ans.a[i] = a[i]-other.a[i]-c;
            if(ans.a[i] < 0)
            {
                c=1;ans.a[i]+=10;
            }
        }
        while(ans.a[ans.n-1] == 0)ans.n--;
        return ans;
    }
    HN operator * (const HN &other)
    {
        HN ans;
        int m = other.n;
        for(int i=0; i<n; i++)
        {
            for(int j=0; j<m; j++)
            {
                ans.a[i+j] += a[i]*other.a[j];
            }
        }
        int c = 0;
        for(int i=0; i<n+m-1; i++)
        {
            ans.a[i]+=c;
            c = ans.a[i]/10;
            ans.a[i]%=10;
        }
        ans.n = n+m-1;
        if(c)
        {
            ans.a[ans.n++] = c%10;
            c/=10;
        }
        if(c)ans.a[ans.n++] = c;
        return ans;
    }
    void print()
    {
        for(int i=n-1; i>=0; i--)
            printf("%d", a[i]);
        printf("\n");
    }
};

HN p2[NMAX+5];

int main()
{
    freopen("indep.in", "r", stdin);
    freopen("indep.out", "w", stdout);
    int n;
    scanf("%d", &n);
    int Max = -1;
    for(int i=0; i<n; i++)
    {
        scanf("%d", &a[i]);
        Max = max(Max, a[i]);
    }
    HN p = 1;
    for(int i=0; i<=n; i++)
    {
        p2[i] = p;
        p = p*(HN)2;
    }
    HN Ans;
    for(int i=2; i<=Max; i++)
    {
        int lim = (int)sqrt(1.0*i);
        int pos = 0, e = 0;
        int c = i;
        bool ok = true;
        while(primes[pos]<=lim)
        {
            if(c%primes[pos] == 0)
            {
                c/=primes[pos];
                e++;
            }
            if(c%primes[pos] == 0)
            {
                ok = false;
                break;
            }
            pos++;
        }
        if(!ok)continue;
        int nr = 0;
        for(int j=0; j<n; j++)
            if(a[j]%i == 0)
                nr++;
        if(c>1)e++;
        if(e%2==1)
        {
            Ans = Ans + p2[nr];
            Ans = Ans - (HN)1;
        }
        else
        {
            Ans = Ans - p2[nr];
            Ans = Ans + (HN)1;
        }
    }
    Ans = p2[n] - Ans;
    Ans = Ans - 1;
    Ans.print();
    return 0;
}