Cod sursa(job #3130193)

Utilizator divadddDavid Curca divaddd Data 17 mai 2023 00:49:49
Problema Indep Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.36 kb
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 502;
const int VMAX = 1002;
int n,a[NMAX],vf[VMAX],f[VMAX],cnt[VMAX];
/// vf[i] = cate nr sunt divizibile cu i
/// cate subsiruri care au cmmdc i = 2^vf[i]
/// ans = (# total de subsiruri) - (# de subsiruri cu cmmdc != 1)
/// f[i] = 0 daca i e liber de patrat
///        1 caz contrar
/// cnt[i] = nr de factori primi din descompunere

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

int main()
{
    for(int i = 2; i < VMAX; i++){
        if(cnt[i] == 0){
            cnt[i]++;
            for(int j = i+i; j < VMAX; j += i){
                cnt[j]++;
            }
            for(int j = i*i; j < VMAX; j *= i){
                f[j] = 1;
            }
        }
    }
    fin >> n;
    for(int i = 1; i <= n; i++){
        fin >> a[i];
        for(int d = 1; d*d <= a[i]; d++){
            if(a[i]%d == 0){
                vf[d]++;
                if(d != a[i]/d){
                    vf[a[i]/d]++;
                }
            }
        }
    }
    int ans = (1<<n)-1;
    for(int i = 2; i < VMAX; i++){
        if(!f[i]){
            if(vf[i] > 0){
                if(cnt[i]%2){
                    ans -= (1<<vf[i])-1;
                }else{
                    ans += (1<<vf[i])-1;
                }
            }
        }
    }
    fout << ans;
    return 0;
}