Cod sursa(job #2180015)

Utilizator giotoPopescu Ioan gioto Data 20 martie 2018 16:16:41
Problema Light2 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <bits/stdc++.h>
using namespace std;

int k;
int a[25];
long long Sol;
long long n;
set <int> S;
inline void back(int nr, int j, long long x){
    if(x > n) return ;
    if(x > 1){
        if(nr % 2 == 1){
            Sol = Sol + 1LL * nr * n / x;
        }
        else{
            Sol = Sol - 1LL * nr * n / x;
        }
    }
    for(int i = j; i <= k ; ++i)
        back(nr + 1, i + 1, x * a[i]);
}
int main(){
    freopen("light2.in", "r", stdin);
    freopen("light2.out", "w", stdout);
    scanf("%lld", &n);
    scanf("%d", &k);
    int x;
    for(int i = 1; i <= n ; ++i){
        scanf("%d", &x);
        if(S.find(x) == S.end()) S.insert(x);
        else S.erase(x);
    }
    k = 0;
    for(auto it : S)
        a[++k] = it;
    back(0, 1, 1);
    printf("%lld", Sol);
    return 0;
}