• + 0 comments
    long primeXor(vector<int> arr) {
        vector<bool> prime(8192, true);
        prime[0] = false, prime[1] = false;
        for (int p = 2; p*p <= 8191; p++) {
            if (prime[p] == true) {
                for (int i = p*p; i <= 8191; i += p)
                    prime[i] = false;
            }
        }
        long total = 0, mod = 1000000007;
        vector<long> counter(8192);
        vector<int> dupe(4501), unique;
        for (int i=0; i < arr.size(); i++) {
            if (dupe[arr[i]] == 0) unique.push_back(arr[i]);
            dupe[arr[i]]++;
        }
        counter[0] = 1;
        for (int i=0; i < unique.size(); i++) {
            vector<long> temporary = counter;
            int F = dupe[unique[i]]/2;
            for (int j=0; j < 8192; j++) {
                int K = unique[i]^j;
                counter[j] = (counter[j] + temporary[j]*F) % mod;
                if (dupe[unique[i]] % 2 == 0) {
                    counter[K] = (counter[K] + temporary[j]*F) % mod;
                } else {
                    counter[K] = (counter[K] + temporary[j]*(F+1)) % mod;
                }
            }
        }
        for (int i=0; i < counter.size(); i++) {
            if (prime[i]) total = (total + counter[i]) % mod;
        }
        return total;
    }