Cod sursa(job #2465647)

Utilizator CyborgSquirrelJardan Andrei CyborgSquirrel Data 30 septembrie 2019 17:58:49
Problema Indep Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>
 
using namespace std;
 
ifstream fin("indep.in");
ofstream fout("indep.out");

typedef long long lint;
 
lint gcd(lint a, lint b){
    if(a == 0){
        return b;
    }
    return gcd(b%a, a);
}
 
int n;
int frecc[1041];
 
lint kapow(lint a, lint p){
    lint r = 1;
    for(int i = 0; i < p; i++){
        r *= a;
    }
    return r;
}
 
lint susta(lint a){
    if(frecc[a] > 0){
        int d, nd;
        d = nd = 0;
        for(int i = a+1; i <= 1000; i++){
            if(gcd(a,i) != 1){
                d += frecc[i];
            }else{
                nd += frecc[i];
            }
        }
        //cout << a << " " << nd  << " " << d << " " << (kapow(2, nd)-1) * kapow(2, d) << "\n";
        return (kapow(2, nd)-1) * kapow(2, d);
    }else{
        return 0;
    }
}
 
int main(){
    int a;
    fin >> n;
    for(int i = 0; i < n; i++){
        fin >> a;
        frecc[a]++;
    }
    
    lint sol = 0;
    for(int i = 2; i <= 1000; i++){
        sol += susta(i);
    }
    fout << sol;
    return 0;
}