Cod sursa(job #1774074)

Utilizator ionanghelinaIonut Anghelina ionanghelina Data 8 octombrie 2016 15:30:32
Problema Indep Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 3.16 kb
#include<bits/stdc++.h>
#define baza 10000
using namespace std;
int n;
int v[505],X[1005],Y[1005],maxim,x,nr,e,j,l;
int vect[1500],solutie[1500],aux[1500];
void copiere(int a[],int b[])
{
    int x=a[0];
    for(int i=0;i<=b[0];i++) a[i]=b[i];
    for(int i=(b[0]+1);i<=x;i++) a[i]=0;
}
void scrie(int x)
{
    if(x<10) printf("000%d",x);
        else
    if(x<100) printf("00%d",x);
        else
    if(x<1000) printf("0%d",x);
        else printf("%d",x);
}
void conversie(int a[],int x)
{
    int da=0;
    while(x)
    {
        a[++da]=x%10;
        x/=10;
    }
    a[0]=da;
}
void adunare(int a[],int b[])
{
    int t=0,i;
    for(i=1;i<=a[0] || i<=b[0] || t;i++)
    {
        t=t+a[i]+b[i];
        a[i]=t%baza;
        t/=baza;
    }
    a[0]=i-1;
}
void inmultire(int a[],int x)
{
    int t=0,i;
    for(i=1;i<=a[0] || t;i++)
    {
        t=t+a[i]*x;
        a[i]=t%baza;
        t/=baza;
    }
    a[0]=i-1;
}
void scadere(int a[],int b[])
{
    int t=0,i;
    for (i=1;i<=a[0];i++)
    {
        a[i]-=(i<=b[0]?b[i]:0);
        a[i]-=t;
        a[i]+=(t=(a[i]<0))*baza;
    }
    while (a[0] && !a[a[0]]) a[0]--;
}
bool ok;
inline int max(int a,int b)
{
    return a>b?a:b;
}
int main()
{
    freopen("indep.in","r",stdin);
    freopen("indep.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&v[i]);
        maxim=max(maxim,v[i]);
    }
    conversie(aux,1);
   // memset(solutie,0,sizeof(solutie));
    for(int i=2;i<=maxim;i++)
    {
        x=i;
        nr=0;
        e=0;
        j=2;
        ok=1;
        while(ok && x>1 && (j*j)<=x)
        {
            if(!(x%j))
            {
                nr++;
                e=0;
                while(!(x%j))
                {
                    e++;
                    x/=j;
                }
            }
            if(e>1) ok=0;
            j++;
        }
        if(x>1)
        {
            nr++;
        }
        if(ok)
        {
            l++;
            X[l]=i;
            Y[l]=nr;
        }
    }
    long long sol=0;
    for(int i=1;i<=l;i++)
    {
        nr=0;
        for(int j=1;j<=n;j++)
        {
            if(!(v[j]%X[i]))
            {
                nr++;
            }
        }
        if(!(Y[i]%2))
        {
            copiere(vect,aux);
           // conversie(vect,1);
            for(int k=1;k<=nr;k++)
            {
                inmultire(vect,2);
            }
            scadere(solutie,vect);
            adunare(solutie,aux);
        }
            else
        {
            copiere(vect,aux);
            for(int k=1;k<=nr;k++)
            {
                inmultire(vect,2);
            }
            adunare(solutie,vect);
            scadere(solutie,aux);
        }
       // sol=sol-(1<<nr)+1;
        //    else sol=sol+(1<<nr)-1;
    }
    copiere(vect,aux);
    for(int i=1;i<=n;i++)
    {
        inmultire(vect,2);
    }
    scadere(vect,aux);
    scadere(vect,solutie);
    printf("%d",vect[vect[0]]);
    for(int i=vect[0]-1;i>=1;i--)
    {
        scrie(vect[i]);
    }
    printf("\n");
    return 0;
}